.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

how to upload default image into database when no image file is selected from fileupload control in

Posted By: parthiban     Posted Date: May 08, 2013    Points:5   Category :ASP.Net
i have to insert default image into databse..when no image is selected from fileupload control..

here is code...not working for default image...

if (FileUpload1.HasFile)
string FileName = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.SaveAs(Server.MapPath("~/UPLOADEDFILES/" + FileName));
feedBack.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileName));

string filename="~/images/"+ "sun.gif";
filename.pPropertyImage = filename;


Author: Faizal             
Posted Date: May 14, 2013     Points: 20   

I guess its bad idea to upload default image when user has not selected any..its better to check if the image column is null in client side show default image..with this approach you can save Database space too.

Author: hark             
Posted Date: March 30, 2014     Points: 20   
Author: vamsi             
Posted Date: July 13, 2014     Points: 20   

you can use the below code

Byte[] imgByte = null;
if (FileUpload1.HasFile && FileUpload1.PostedFile.ContentLength < 1055799)
HttpPostedFile File = FileUpload1.PostedFile;
imgByte = new Byte[File.ContentLength];
File.InputStream.Read(imgByte, 0, File.ContentLength);
FileInfo _fileInfo = new FileInfo(Server.MapPath("~") + "\\App_Folder\\Content\\AboutUs\\Images\\Logo.jpg");
FileStream _fileStream = new FileStream(_fileInfo.FullName, FileMode.Open);
imgByte = new Byte[_fileStream.Length];
_fileStream.Read(imgByte, 0, Convert.ToInt32(_fileStream.Length));

send "imgByte" in insertcommend

For more visit http://www.dotnetchallengers.com/

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend