all groups > vb.net controls > may 2007 >
You're in the

vb.net controls

group:

problem with checking FileUpload



problem with checking FileUpload Bart
5/28/2007 7:10:15 PM
vb.net controls: 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


Re: problem with checking FileUpload John Timney (MVP)
5/28/2007 10:38:59 PM
You should save the file on the server first as a tempoirary file, and then
present the information that the file already exists. If yes, replace the
existing file - if no delete the temp one.

Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog


[quoted text, click to view]

Re: problem with checking FileUpload Bart
5/29/2007 12:49:51 AM
Thanks


"John Timney (MVP)" <x_john@timney.eclipse.co.uk> schreef in bericht
news:MpmdnaKJ2btu1sbbnZ2dnUVZ8vWdnZ2d@eclipse.net.uk...
[quoted text, click to view]

AddThis Social Bookmark Button