Click here to Skip to main content
15,127,310 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am using file Fileupload asp.net control for uploading file ,after browsing files
when I'll click upload button it clears the selected file.

What I have tried:



<asp:FileUpload ID="FileUpload1" runat="server" />


<asp:Button ID="Button1" runat="server" Text="Upload" CausesValidation="false" />




In code Behind,
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If (FileUpload1.HasFile) Then
DtTable3 = Session("DtTable3")
Dim FileName As String = Path.GetFileName(FileUpload1.PostedFile.FileName)
FileName = txtCustItemCode.Text + FileName
For Each drRow In DtTable3.Rows
If Trim(drRow("Filename")) = FileName Then
uscMsgBox1.AddMessage(Trim(FileName) & "This File is already exist", UserControls_uscMessageBox.enmMessageType.Error)
Exit Sub
End If
Next
Dim Extension As String = Path.GetExtension(FileUpload1.PostedFile.FileName)
Dim FolderPath As String = ConfigurationManager.AppSettings("FolderPath")
Dim FilePath As String = Server.MapPath(FolderPath + FileName)
FileUpload1.SaveAs(FilePath)
drRow = DtTable3.NewRow
drRow.Item("Filename") = FileName
drRow.Item("FilePath") = FilePath
DtTable3.Rows.Add(drRow)
Session("DtTable3") = DtTable3

Else
uscMsgBox1.AddMessage("Select File cilck on browse button", UserControls_uscMessageBox.enmMessageType.Info)
End If
End Sub
After running it will give output as following always :
Select File cilck on browse button.
Posted
Updated 22-Jun-17 0:43am

It does this for security reasons, there is no way to get around it.
   
I use <triggers> in update panel & outside of content Template its work
<triggers>
<asp:PostBackTrigger ControlID="Button1">
   
v2
Comments
F-ES Sitecore 22-Jun-17 6:04am
   
So you were using an UpdatePanel and you didn't think that was relevant enough to mention? FileUpload doesn't work inside an asynch updatepanel and by using a PostBackTrigger you are effectively making the updatepanel non-asynchronous so there is no point in using the updatepanel at all.

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