Question

i have been working trying to find the answers for this but i cant find any solutions that worked.

MultipleFileUploader.ascx:
     <asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
        </asp:ScriptManagerProxy>  
    <asp:UpdatePanel ID="UpdatePanel1"  runat="server">
        <ContentTemplate>
    <asp:FileUpload ID="FileUpload1" runat="server" 
                    multiple="multiple" onchange="__doPostBack('<%= UpdatePanel1.ClientID %>', ''); type="file" />
      </ContentTemplate>
    </asp:UpdatePanel>

Behind Codes:

 protected void Page_Load(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
            onAttach();
    }

It uploads the file the moment the user selects a file with the Postback __doPostBack It shouldnt be browser issue because im getting the same problem on chrome firefox and IE. The codes has always been working fine till we upgraded to .net 4.0, for some reason it FileUploader.HasFile always return false.

I have tried:

Page.Form.Attributes.Add("enctype", "multipart/form-data"); 

and :

<Triggers> 
   <asp:PostBackTrigger ControlID="btnUploadFile" /> 
</Triggers> 

Am i missing something simple or anything? Any help rendered is very much appreciated. Many Thanks.

Was it helpful?

Solution

Did you placed the trigger inside <update panel> like

<asp:UpdatePanel ID="UpdatePanel1"  runat="server">
  <Triggers> 
    <asp:PostBackTrigger ControlID="btnUploadFile" /> 
  </Triggers> 
 <rest of the code>
</asp:UpdatePanel>

Taken from this post FileUpload.hasFile is always False

If it's still not working then try placing your FileUpload control outside UpdatePanel and see if it works. Reasoning: you should not be placing a FileUpload control inside an UpdatePanel because the UpdatePanel sends an AJAX request to the server.

Make sure that the credential using which you are running web application has access to the file. In other words it's not a file permission issue.

you can also use FileUpload controls FileName property like

if (FileUpload1.FileName != string.Empty) 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top