HTMLInputFile (Posted) file: Object reference not set Error

M

mravichandran

Dear Readers,

I am trying to take image files and store them in SQL server. as a 1st
step, I am trying to read them from a directory on the network.

in the declaration section (below the class declaration) I have:

protected System.Web.UI.HtmlControls.HtmlInputFile ImageFile;

inside the function button_click: I have

ImageFile = new HtmlInputFile();

string strFileName = "";
strFileName= ImageFile.PostedFile.FileName;

on exectuing the "strFileName = Image..." statement, it gives the
following error:
**********************************
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.

Source Error:

Line 80:
Line 81: string strFileName = "";
Line 82: strFileName= ImageFile.PostedFile.FileName;
Line 83: string strFilePath = Path.GetFileName(strFileName);
*******************************
any help will be appreciated.

thanks and regards
Ravi.
 
K

Kevin Spencer

An HtmlInputFile Control is a UI element that provides a form field for
uploading files from a browser. You have no business using an HtmlInputFile
if you're trying to read files from the file system. Use System.IO classes
instead.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top