You must Sign In to post a response.
  • Category: ASP.NET

    Object reference not set to an instance of an object.

    I'm getting " Object reference not set to an instance of an object " error while uploading a file in c#.

    Please help me..
    With Regards


    My Code:

    <script runat="server">
    protected void Button1_Click(object sender, EventArgs e)
    WebUI2.SaveFile sf = new WebUI2.SaveFile();

    if (FileUpload1.HasFile)
    sf.fileName = FileUpload1.PostedFile.FileName;
    sf.fileExtension = Path.GetExtension(FileUpload1.PostedFile.FileName); = FileUpload1.FileBytes;

    Label1.Text = sf.SaveFileToDB();
  • #761200

    Object reference not set to an instance of an object

    Mostly we need to new instance then fileupload control did not get filename value did not correct properly

    check this
    Fileupload control name is correct or not then when you can upload filename get properly.

    Name : Dotnet Developer-2015
    Email Id

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #761212

    As per error description if you are assign null value to some object in that case you are getting this error. My suggestion is better to debug code and check which line you are getting this error, and see the right hand side value of that particular line.

    Hope this will helpful to you...

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #761234
    Hi sathik,

    This type of error arises when you have not defined or initialized your method objects properly.

    May be your parameters sf.fileName, sf.fileExtension, are not defined properly or are not initialized. So the error is coming.

    You can debug to check which line is throwing error.

Sign In to post your comments