Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. FileUpload.HasFile is always false

FileUpload.HasFile is always false

Scheduled Pinned Locked Moved ASP.NET
asp-netcsharpquestion
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bill Warner
    wrote on last edited by
    #1

    Hi, I have an asp.net web forms project. No master pages, no ajax, I have a file upload control and when I fire postback the HasFiles property is always empty. I started a new asp.net project. Copy/Pasted the code into it and it worked. HasFiles was retained. Does anyone know why? The code:

    protected void Page_Init(object sender, EventArgs e)
    {
    if(IsPostBack) return;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
    if(flImage.HasFile){
    Application["FileBytes"] = flImage.FileBytes;
    Application["FileContent"] = flImage.FileContent;
    Application["FileName"] = flImage.FileName;
    Application["PostedFile"] = flImage.PostedFile;
    }

    HasFile is always false.

    Richard DeemingR L B D 4 Replies Last reply
    0
    • B Bill Warner

      Hi, I have an asp.net web forms project. No master pages, no ajax, I have a file upload control and when I fire postback the HasFiles property is always empty. I started a new asp.net project. Copy/Pasted the code into it and it worked. HasFiles was retained. Does anyone know why? The code:

      protected void Page_Init(object sender, EventArgs e)
      {
      if(IsPostBack) return;
      }

      protected void Page_Load(object sender, EventArgs e)
      {
      if(flImage.HasFile){
      Application["FileBytes"] = flImage.FileBytes;
      Application["FileContent"] = flImage.FileContent;
      Application["FileName"] = flImage.FileName;
      Application["PostedFile"] = flImage.PostedFile;
      }

      HasFile is always false.

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Whoops! Looks like you've broken the forum. Please edit your post and either remove or HTML-encode the <table> and other HTML tags in your question. The quickest option is to select the entire block of code and click the "code" button in the editor toolbar.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      • B Bill Warner

        Hi, I have an asp.net web forms project. No master pages, no ajax, I have a file upload control and when I fire postback the HasFiles property is always empty. I started a new asp.net project. Copy/Pasted the code into it and it worked. HasFiles was retained. Does anyone know why? The code:

        protected void Page_Init(object sender, EventArgs e)
        {
        if(IsPostBack) return;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
        if(flImage.HasFile){
        Application["FileBytes"] = flImage.FileBytes;
        Application["FileContent"] = flImage.FileContent;
        Application["FileName"] = flImage.FileName;
        Application["PostedFile"] = flImage.PostedFile;
        }

        HasFile is always false.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        You may want to edit your post, it has caused some weird behaviour in its formatting. Try putting your code between <pre> tags to see if that fixes it.

        Use the best guess

        1 Reply Last reply
        0
        • B Bill Warner

          Hi, I have an asp.net web forms project. No master pages, no ajax, I have a file upload control and when I fire postback the HasFiles property is always empty. I started a new asp.net project. Copy/Pasted the code into it and it worked. HasFiles was retained. Does anyone know why? The code:

          protected void Page_Init(object sender, EventArgs e)
          {
          if(IsPostBack) return;
          }

          protected void Page_Load(object sender, EventArgs e)
          {
          if(flImage.HasFile){
          Application["FileBytes"] = flImage.FileBytes;
          Application["FileContent"] = flImage.FileContent;
          Application["FileName"] = flImage.FileName;
          Application["PostedFile"] = flImage.PostedFile;
          }

          HasFile is always false.

          B Offline
          B Offline
          Bernhard Hiller
          wrote on last edited by
          #4

          Move your code from Page_Load to the Click event handler of the submit button, remove the EnableViewState property, and try again. Not sure if that's the reason, at least, it works in my projects.

          1 Reply Last reply
          0
          • B Bill Warner

            Hi, I have an asp.net web forms project. No master pages, no ajax, I have a file upload control and when I fire postback the HasFiles property is always empty. I started a new asp.net project. Copy/Pasted the code into it and it worked. HasFiles was retained. Does anyone know why? The code:

            protected void Page_Init(object sender, EventArgs e)
            {
            if(IsPostBack) return;
            }

            protected void Page_Load(object sender, EventArgs e)
            {
            if(flImage.HasFile){
            Application["FileBytes"] = flImage.FileBytes;
            Application["FileContent"] = flImage.FileContent;
            Application["FileName"] = flImage.FileName;
            Application["PostedFile"] = flImage.PostedFile;
            }

            HasFile is always false.

            D Offline
            D Offline
            Dholakiya Ankit
            wrote on last edited by
            #5

            hello pls try this circumstances 1 >> check that if you have updatepanel then you have applied trigger on that one 2 >> check that your page load have !isnotpostback and if yes then in that file upload is not getting null this should be issues may be regards...:)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups