Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to set a default image path in fileupload control in asp.net.
Posted

if (FileUpload = "")
   img.imgUrl = "default.jpg";
else
   img.imgUrl = FileUpload.Path;
 
Share this answer
 
Comments
BALBINDER4u 19-Dec-12 2:55am    
please check my code

System.Drawing.Image imag = System.Drawing.Image.FromStream(Fileupload1.PostedFile.InputStream);



cmd.Parameters.Add("@image", SqlDbType.Image, 0).Value = ConvertImageToByteArray(imag, System.Drawing.Imaging.ImageFormat.Jpeg);





private byte[] ConvertImageToByteArray(System.Drawing.Image imageToConvert, System.Drawing.Imaging.ImageFormat formatOfImage)
{
byte[] Ret;
try
{
using (MemoryStream ms = new MemoryStream())
{
imageToConvert.Save(ms, formatOfImage);
Ret = ms.ToArray();
}
}
catch (Exception) { throw; }
return Ret;
}


In this code i have one fileupload control.
I want that then user not select their photo then default photo (Avatar.jpg)file save in the database.
I dunno what the other guy is saying, but you can't set the path to a file upload control, because if you could, you could hide one on your page with the path to a system file and hack someone's system that way. You can't set it in js or in your html.
 
Share this answer
 
Comments
BALBINDER4u 19-Dec-12 2:56am    
please check my code

System.Drawing.Image imag = System.Drawing.Image.FromStream(Fileupload1.PostedFile.InputStream);



cmd.Parameters.Add("@image", SqlDbType.Image, 0).Value = ConvertImageToByteArray(imag, System.Drawing.Imaging.ImageFormat.Jpeg);





private byte[] ConvertImageToByteArray(System.Drawing.Image imageToConvert, System.Drawing.Imaging.ImageFormat formatOfImage)
{
byte[] Ret;
try
{
using (MemoryStream ms = new MemoryStream())
{
imageToConvert.Save(ms, formatOfImage);
Ret = ms.ToArray();
}
}
catch (Exception) { throw; }
return Ret;
}


In this code i have one fileupload control.
I want that then user not select their photo then default photo (Avatar.jpg)file save in the database.
Christian Graus 19-Dec-12 14:47pm    
So, if they don't select a photo, push in your avatar. That means the upload control is blank. If it had the name of the default image, that file would need to exist on the client

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