.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Upload image to database - couldn't find file path

Posted By:      Posted Date: September 08, 2010    Points: 0   Category :ASP.Net
I'm trying to display images in a GridView (yes, still this...). [edit] Before I can come to that I have to upload some images to the database.I've followed this tutorial for the "upload image to database" code (this worked fine for uploading images, but I don't know if the images were converted to byte):http://aspsnippets.com/Articles/Save-Files-to-SQL-Server-Database-using-FileUpload-Control.aspxand I've followed this tutorial for the "display images in gridview" code (and "retrieve file" from the tutorial below).http://www.aspsnippets.com/Articles/Display-images-from-SQL-Server-Database-in-ASP.Net-GridView-control.aspxIt doesn't quite work, the GridView shows but without imagesNow I'm trying to change the "save file" code according to this tutorial:http://aspsnippets.com/Articles/Save-and-Retrieve-Files-from-SQL-Server-Database-using-ASP.Net.aspxbut I don't understand everything in it. When I try to upload an image I get an error on this line:FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); //couldn't find file (path to image I tried to upload) What should I do about it?

View Complete Post

More Related Resource Links

How to upload a file to web server in asp.net and store file path into database table?

This article describe how to upload a file into web server folder using asp.net file upload control and store the file information into sql server database.

ASP.Net Upload Image to MS Access Database

As you learnt from the previous articles to upload image to the SQL Database in ASP.Net 2.0 and stream that image into the memory to retrieve it from the database and display it on the web page. In this article you will learn how to upload images to the MS Access database in ASP.Net 2.0

First of all create an Access Database and place it in the App_Data folder of ASP.Net web site project. Then create a table "tblImg" with the following fields:

How do I find the file path from a namespace.class name?


I'm programatically looking ito a .aspx file and getting the file class name declared in its CodeBehind. For example, when analyzing myFile.aspx I read in its Page Directive and found its CodeBehind equals "myApplication\myPage.aspx.vb". Then I use the code below:


Dim Assm As System.Reflection.Assembly = System.Reflection.Assembly.LoadFrom("myApplication\bin\myApplication.dll")
Dim ClassType As Type = Assm.GetType("myApplication\myPage.aspx.vb")
' myBaseType = "myApplication.Forms.BasePage"
Dim myBaseType As System.Type = ClassType.BaseType


Now I want to read the BaseFile (class = myApplication.Forms.BasePage). However, to read in this file, I need I need to get its full path instead of its namespace.class hiearchy. In this case, the BasePage is wrapped in a different namespace declaration thus I cannot just change the '.' to '\' in order to get the path.

How can I get the path of BasePage so I can read it? Thank you - Frank

Acces the file upload path

how can i acces the file upload text. I mean if i choose a file , then the file path comes in file upload e.g. c:/data/fil1.txt.All i want to acces this full path and show in a label.

Insert Excel Data via File Upload into sql server database???

Hi all, I have requirement that User can Upload the Excel Sheet Data to sql server Database at once. How i do that Any Article or hint is apperciated.   Regards 

Path to sqlite database file

Hy,i want access to my database sqlite file from web.config file I've added connection string in web.config but my format is wrong. My database file existx in App_Data Folder.How to add path independet of drive, for example:<connectionStrings>         <add name="CROexport" connectionString="~\App_Data\CROexport.db3;Version=3;" providerName="System.Data.SQLite"/>     </connectionStrings><connectionStrings> <add name="Name" connectionString="~\App_Data\DbFile.db3;Version=3;" providerName="System.Data.SQLite"/> </connectionStrings>I want relative path?I've tried "../../App_Data/", "|App_Data|"

Upload file to server or database

hi,I'd like to know how to allow user to upload file to the server in mvc 2 application. I haven't seen a very clear tutorial for this, at least not on this website. There is a movie database tutorial but that is simply a list of movies not actual files. What is the simplest method for uploading files, be they images or movies? Thank you for your time.

File Upload to database (and download)



How can I upload a file to a database (with as little code as possible!) along with a desciption of a file and then search through the descriptions to retrieve the appropriate files. Then how can I click on one and download it.

I am not a very advanced programmer and would like full step by step code if possible not just a link to a website.

Thank you very much


Dispaly image from Ms access database to rdlc file


hi all,

    I have done website using Ms access database and VS2005. actually i store image in system.byte[] format in MS access database..so i want to set that image in rdlc background or image tag.

actually  i did the following way..

  OdbcCommand commad = new OdbcCommand("Select img_stream from Key", con);
               OdbcDataReader dr1 = commad.ExecuteReader();

                OdbcDataAdapter myAdapter = new OdbcDataAdapter(commad);
                DataSet myDataSet = new DataSet();
                byte[] imageContent = null;
                foreach (DataRow dRow in myDataSet.Tables["Key"].Rows)
                    if (dRow["img_stream"] != DBNull.Value)

                       imageContent = (byte[])dRow["img_stream"];

                    byte[] imageContent1 = (byte[])((dRow["img_stream"]));


  this.reportViewer1.LocalReport.ReportEmbeddedResource = "Taegutec.Report2.rdlc";
this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1_Key", myAdapter));

but i got following Exception

ex = {"Value does not fall within the expected ra

Can i upload file to database table using AsyncFileUpload ?



can i upload my pdf or word file to oracle/SqlServer database table ?

How ? 

on file upload image preview in asp.net



when  a Image is uploaded immediately the image preview should display in image control or html image in asp.net.

I try but in all browsers its not working.

pls tell me how to do this task and the image preview should display in all browsers.

Many Thanks in Advance.

How to insert Database and Upload file


I have TBL_PRODUCT table : ProductID, ProductName, CategoryID, Image.

I can insert data to table :

public ActionResult Create(tbl_products products)

       return Redirect("Index");

I can upload image file too

public ActionResult UpHinh(HttpPostedFileBase fileImg)
       var fileName = Path.GetFileName(fileImg.FileName);
       fileImg.SaveAs(Server.MapPath("/Content/Images/" + fileName));

       return Redirect("Index");

But I want two function become one. When I press <Submit>, it's insert data and upload image file.

Help me. Thanks

File Upload to Database


Hi All

I'm using a DetailsView control and have a FileUpload control in a TemplateField for uploading images to a database.

However, I'm not sure how to take the image name e.g. Button.png as a value and enter it into the database.

Thanks for your help.

Uploading .pdf files with FIle Upload control and then saving to database


Hi everyone!

I'd like to allow users to upload a .pdf file via the file upload control (if that's the best method), save the file to the db and then retrieve it so they can click on a link and open the .pdf they've uploaded.

I've been looking for a tutorial on how to do this but keep running into methods of saving the file directly on the server in a directory, not in SQL server  (using Linq and VB by the way)

Can someone please point me in the right direction on how to do this?   Thanks!

INSERT NULL value in SQL database when there is no file to upload



I've been working on a code that allows users to upload images (jpgs) as an optional field. Alhough the uploading works, I'm struggling when the user doesn't have an image to upload. I can't seem to find the way to NOT insert binary data into my database, I just want an NULL value when there is no image.
I get this error message: ...expects parameter @Image, which was not supplied.


Here is the code: 

Sub InsertItem()

Dim imageData As Byte() = Nothing
Dim MIMEType As String = ""


Upload an Image and an Audio file using C#

The article Upload an Image and an Audio file using C# was added by miya2008 on Saturday, October 30, 2010.

In my case, I use a FileUpload Control(Id:->FileUpload1), an ImageButton(ImageButton1) or you can use the Image, a Button Control(Id:->Updatebttn) to upload my Image, Button Control(Id:->Addbttn) to add my Image in database, an image(which I

Upload Multiple File using JQuery in asp.net

In this article I have explained how to upload multiple files using file upload control. I have used jQuery plugin for uploading multiple files.

I have also explained how to check for file type, file maximum size limit using jQuery & also using server side validation code.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend