HTMLInputFile (Posted) file: Object reference not set Error

Discussion in 'ASP .Net' started by mravichandran@gmail.com, Dec 13, 2004.

  1. Guest

    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.
     
    , Dec 13, 2004
    #1
    1. Advertising

  2. 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.

    <> wrote in message
    news:...
    > 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.
    >
     
    Kevin Spencer, Dec 13, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Parthiv Joshi
    Replies:
    2
    Views:
    717
    Kalyan
    Jul 2, 2004
  2. Suresh Kojhani
    Replies:
    1
    Views:
    2,424
    Anushi
    Jul 29, 2004
  3. Pedro Correia
    Replies:
    0
    Views:
    642
    Pedro Correia
    Jul 25, 2003
  4. Lauchlan M
    Replies:
    1
    Views:
    2,388
    S. Justin Gengo
    Aug 18, 2003
  5. Replies:
    1
    Views:
    514
    Mark Rae [MVP]
    Sep 20, 2007
Loading...

Share This Page