problem with checking FileUpload

B

Bart

Hi,

i use the FileUpload control but if the uploaded file already exists, i want
let the choice between overwriting or not the existing file.
Therefore i use a radiobuttonlist with 'yes' and 'no'.

I get no error, but if i take 'yes', the new file which overwrites the
existing one is empty. I think it's because of the postabck caused by the
radiobuttonlist, so the Fileupload control looses the chosen file. I put the
FileUpLoad1.FileName in a hiddenfield in order to get it back after the 2nd
postback, but no succes.

Thanks for help
Bart

Here my code:
aspx:
<asp:FileUpLoad id="FileUpLoad1" runat="server" /><br /><br />
<asp:Button id="Button1" Text="Opladen" runat="server" /><br /><br
/>
<asp:Label id="Label1" runat="server" />
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
Visible=false AutoPostBack=true>
<asp:ListItem Value="ja" Text="ja" ></asp:ListItem>
<asp:ListItem Value="nee" Text="nee" ></asp:ListItem>
</asp:RadioButtonList>

code-behind:

Protected Sub Button1_Click1(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
If FileUpLoad1.HasFile Then
If File.Exists(Server.MapPath("~/uploaddir/" &
FileUpLoad1.FileName)) Then
HiddenField1.Value = FileUpLoad1.FileName
Label1.Text = FileUpLoad1.FileName & " is already on server.
Overwrite?"
RadioButtonList1.Visible = True
Else
Label1.Visible = False
FileUpLoad1.SaveAs(Server.MapPath("~/uploaddir/" &
FileUpLoad1.FileName))
End If
End If
End Sub

Protected Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
RadioButtonList1.SelectedIndexChanged
If RadioButtonList1.SelectedValue = "yes" Then
Label1.Visible = False
FileUpLoad1.SaveAs(Server.MapPath("~/uploaddir/" &
HiddenField1.Value))
Else
RadioButtonList1.Visible = False
Label1.Visible = False
End If
End Sub
End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top