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.Fil eName 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:FileUpLo ad id="FileUpLoad1 " runat="server" /><br /><br />
<asp:Button id="Button1" Text="Opladen" runat="server" /><br /><br
/>
<asp:Label id="Label1" runat="server" />
<asp:HiddenFiel d ID="HiddenField 1" runat="server" />
<asp:RadioButto nList ID="RadioButton List1" runat="server"
Visible=false AutoPostBack=tr ue>
<asp:ListItem Value="ja" Text="ja" ></asp:ListItem>
<asp:ListItem Value="nee" Text="nee" ></asp:ListItem>
</asp:RadioButton List>
code-behind:
Protected Sub Button1_Click1( ByVal sender As Object, ByVal e As
System.EventArg s) Handles Button1.Click
If FileUpLoad1.Has File Then
If File.Exists(Ser ver.MapPath("~/uploaddir/" &
FileUpLoad1.Fil eName)) Then
HiddenField1.Va lue = FileUpLoad1.Fil eName
Label1.Text = FileUpLoad1.Fil eName & " is already on server.
Overwrite?"
RadioButtonList 1.Visible = True
Else
Label1.Visible = False
FileUpLoad1.Sav eAs(Server.MapP ath("~/uploaddir/" &
FileUpLoad1.Fil eName))
End If
End If
End Sub
Protected Sub RadioButtonList 1_SelectedIndex Changed(ByVal sender As
Object, ByVal e As System.EventArg s) Handles
RadioButtonList 1.SelectedIndex Changed
If RadioButtonList 1.SelectedValue = "yes" Then
Label1.Visible = False
FileUpLoad1.Sav eAs(Server.MapP ath("~/uploaddir/" &
HiddenField1.Va lue))
Else
RadioButtonList 1.Visible = False
Label1.Visible = False
End If
End Sub
End Class
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.Fil eName 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:FileUpLo ad id="FileUpLoad1 " runat="server" /><br /><br />
<asp:Button id="Button1" Text="Opladen" runat="server" /><br /><br
/>
<asp:Label id="Label1" runat="server" />
<asp:HiddenFiel d ID="HiddenField 1" runat="server" />
<asp:RadioButto nList ID="RadioButton List1" runat="server"
Visible=false AutoPostBack=tr ue>
<asp:ListItem Value="ja" Text="ja" ></asp:ListItem>
<asp:ListItem Value="nee" Text="nee" ></asp:ListItem>
</asp:RadioButton List>
code-behind:
Protected Sub Button1_Click1( ByVal sender As Object, ByVal e As
System.EventArg s) Handles Button1.Click
If FileUpLoad1.Has File Then
If File.Exists(Ser ver.MapPath("~/uploaddir/" &
FileUpLoad1.Fil eName)) Then
HiddenField1.Va lue = FileUpLoad1.Fil eName
Label1.Text = FileUpLoad1.Fil eName & " is already on server.
Overwrite?"
RadioButtonList 1.Visible = True
Else
Label1.Visible = False
FileUpLoad1.Sav eAs(Server.MapP ath("~/uploaddir/" &
FileUpLoad1.Fil eName))
End If
End If
End Sub
Protected Sub RadioButtonList 1_SelectedIndex Changed(ByVal sender As
Object, ByVal e As System.EventArg s) Handles
RadioButtonList 1.SelectedIndex Changed
If RadioButtonList 1.SelectedValue = "yes" Then
Label1.Visible = False
FileUpLoad1.Sav eAs(Server.MapP ath("~/uploaddir/" &
HiddenField1.Va lue))
Else
RadioButtonList 1.Visible = False
Label1.Visible = False
End If
End Sub
End Class
Comment