Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
dear all,
how to load an image that was saved its path+name in a databas, into FileUpload1 when
no image file is selected from FileUpload1 control in vb.net???
for example:

VB
Dim FileName As String
name="marry"
FileName="~/files/pic/pic1.jpg"

If FileUpload1.HasFile Then
   FileName = "~/files/pic/" + FileUpload1.FileName
   FileUpload1.SaveAs(Server.MapPath("~/files/pic/")+FileUpload1.FileName)
   MyTable.InsertQuery(TXTName.Text, TXTFamily.Text, FileName)
   GridView1.DataBind()
ELSE
   FileUpload1.FileName=FileName  '?????????
   TXTName.Text=name
End If

Line(FileUpload1.FileName=FileName)is wrong. But what code is true with this meaning???
I want a code for replace with upper line, to fill FileUpload1 automatically with out it needs select with user.
thank you
Posted
Updated 20-Oct-13 13:03pm
v2

1 solution

You can't set the FileUpload;s FileName property as it's readonly and you are not allowed to explicitly set the same.

Try doing something like below.

If No image is selected then the FileUpload's Filename property will be empty , so you can do some interesting thing like loading the default image.
 
Share this answer
 
Comments
shamsghamar 20-Oct-13 19:16pm    
how can I do loading the default image?
please enter some codes like "if" statements for "else" statements.
thank you
Ranjan.D 20-Oct-13 19:36pm    
There's no way you can manually set the FileUpload;s FileName property from code behind as it's a readonly property. Not sure you can do some magic in Javascript , still when you resubmit the HasFile will be fase.

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