Uploading an Image
-
Hey Friends, Thnx For the help last time, It was great on your part and the error gor solved. But again have stuck up at a point, where i have to upload the images and store it in the questions database.!the question must be in image format and the answers could also be in image format, and i have to save all this in the question database.! Please Help me out friends.!
-
Hey Friends, Thnx For the help last time, It was great on your part and the error gor solved. But again have stuck up at a point, where i have to upload the images and store it in the questions database.!the question must be in image format and the answers could also be in image format, and i have to save all this in the question database.! Please Help me out friends.!
There are quite a few articles on this topic. Try the following for some tips - Storing images in SQL Server using EF and ASP.NET[^] http://www.dotnetgallery.com/kb/resource21-How-to-store-and-retrieve-images-from-SQL-server-database-using-aspnet.aspx[^]
Apps - Color Analyzer | Arctic | XKCD | Sound Meter | Speed Dial
-
Hey Friends, Thnx For the help last time, It was great on your part and the error gor solved. But again have stuck up at a point, where i have to upload the images and store it in the questions database.!the question must be in image format and the answers could also be in image format, and i have to save all this in the question database.! Please Help me out friends.!
Code To upload Your Image to folder
YourFunctionToUploadImage()
{
//Check FileUpload controll has File Or not
if (ImageFileUploadControll.HasFile)
{
string fileExtention = System.IO.Path.GetExtension(ImageFileUploadControll.FileName);
//Check For Valid Extension
if (fileExtention.ToLower() != ".jpg" && fileExtention.ToLower() != ".jpeg" && fileExtention.ToLower() != ".png")
{
lblUploadstatus.Text = "Invalid File Choose .jpg/.jpeg/.png/.gif";
}
else
{
//check if file already Exists in Folder
if (File.Exists(Server.MapPath("~/Folder_Name/" + ImageFileUploadControll.FileName)))
{
lblUploadstatus.Text = "File Already Exists. Rename filename";
}
else
{
//To Save Image To your Specific Location.
//srever.mappath takes us to Folder which containing our application
ImageFileUploadControll.SaveAs(Server.MapPath("~/Folder_Name/" + ImageFileUploadControll.FileName));
lblUploadstatus.Text = "Upload Status : File Uploaded Successfully";
}
}}
else
{
lblUploadstatus.Text = "Please Select File";
}
}Code To Retrive All Images form Folder and display in image_control you can use
PageLoadEvent()
{
//use DirectoryInfo to get all imageFile's Information
DirectoryInfo dir = new DirectoryInfo(Server.MapPath("~/Folder_Name/"));
FileInfo[] fi = dir.GetFiles();//Now you just need to create new image control each time and add ImageUrl to it foreach(FileInfo f in fi) { string imageUrl = f.ToString(); Image img = new Image(); img.ImageUrl = "~/Folder\_Name/"+"imageUrl"; }
}
Hope This Help
Pratik Bhuva --------------- The night is darkest just before the dawn. And I promise you, the dawn is coming