Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > HTMLInputFile (Posted) file: Object reference not set Error

Reply
Thread Tools

HTMLInputFile (Posted) file: Object reference not set Error

 
 
mravichandran@gmail.com
Guest
Posts: n/a
 
      12-13-2004
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.

 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      12-13-2004
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.

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Object reference not set to an instance of an object" Weird thing happens with reference a link nguyentrongkha@gmail.com ASP .Net 1 09-20-2007 09:46 PM
Error:Object reference not set to an instance of an object. Suresh Kojhani ASP .Net 1 07-29-2004 12:10 PM
Error !Object reference not set to an instance of an object. !!! Help Parthiv Joshi ASP .Net 2 07-02-2004 10:28 AM
"Object reference not set to an instance of an object" error Lauchlan M ASP .Net 1 08-18-2003 01:32 PM
HELP! Error Loading ASPX : Object Reference not set to an instance object Pedro Correia ASP .Net 0 07-25-2003 10:42 AM



Advertisments