Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ASP.NET
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Always" runat="server">
<ContentTemplate>

<div class="controls">
	<asp:FileUpload id="file" CssClass="btn btn-success span3" runat="server" />
</div>
<div class="controls">
	<asp:FileUpload id="file1" CssClass="btn btn-success span3" runat="server" />
</div> 

<asp:Button id="btnSubmit" runat="server" CssClass="btn btnprimary" Text="Submit" OnClientClick="return validate();" OnClick="btnSubmit_click"/>
<asp:Button id="btnUpdate" runat="server" CssClass="btn btn-success" Text="Update" OnClientClick="return validate();" OnClick="btnUpdate_click"/>



<triggers>
    <asp:PostBackTrigger ControlID = "btnSubmit" />
    <asp:PostBackTrigger ControlID = "btnUpdate" />


What I have tried:

above code run perfect localhost but not working online server side
Posted
Updated 4-Nov-16 7:44am
v3

FileUpload doesn't work inside an asynchronous updatepanel. If you want asynch uploads then use a jquery plug-in that supports this, or use the Ajax Toolkit. Google for more info and examples.
 
Share this answer
 
In PageLoad Code Add ..

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


On webpage ....

<asp:updatepanel id="UpdatePanel6" runat="server">
<triggers> <asp:postbacktrigger controlid="btnFileUpload">
<contenttemplate>

 


<asp:fileupload id="FileUpload1" runat="server" width="99%" allowmultiple="True"> <asp:button id="btnFileUpload" runat="server" text="Upload" font-size="x-small" width="75" onclick="btnFileUpload_Click">






In Code Have Upload Handler..

' ---------------------------------------------------------------------------
' UploadButton_Click
' ---------------------------------------------------------------------------
Protected Sub btnFileUpload_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnFileUpload.Click
lblUpLoadErr.Text = ""

Try
If FileUpload1.HasFile Then
For Each fle As HttpPostedFile In FileUpload1.PostedFiles
If ExtCheck(fle.FileName) Then
Dim fileName As String = Path.GetFileName(fle.FileName)

Dim newPath As String = TreeView1.SelectedNode.Value
If Not Directory.Exists(newPath) Then
Directory.CreateDirectory(newPath)
End If
Dim newfullFilename As String = myDir + "\" + fileName
fle.SaveAs(newfullFilename)
Else
lblUpLoadErr.Text += "Illegal Filename,"
End If
Next
lblUpLoadErr.Text = String.Format("{0} files have been uploaded successfully.", FileUpload1.PostedFiles.Count)
LoadFiles()
End If
Catch ex As Exception
lblUpLoadErr.Text = "Error in uploading file." + ex.Message
End Try

End Sub


I have been using this in production for awhile... I also left myDir undefined as that is the path where to store the file..

Regards,
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900