Last post May 26, 2011 07:30 AM by Nandip Makwana
May 26, 2011 04:18 AM|yugz|LINK
I am novice web developer, i need some advice about where to store images
i am working on a project for a Real estate agency and basically i need to store lots of images of houses that are for sale.
do i store these pictures in a database or in a folder?
i personally think it should be stored in a database but i have been advised to use a folder instead
May 26, 2011 05:10 AM|Rajneesh Verma|LINK
It is better to store images in Folder instead of Database.
see some more answers:
May 26, 2011 05:24 AM|Dave Sussman|LINK
Definitely in a folder. Store the names of the images in the database, alongside any other details, but the images themselves should be onthe file system.
May 26, 2011 05:25 AM|thenalimmu|LINK
you can save your images into a folder where you publish your webiste.you can define the path in a database.look at this sample.hope it helps
string cnnstring = "Data Source=XXX\\XXX;Initial Catalog=Surveydb;Integrated Security=True";
SqlConnection con = new SqlConnection(cnnstring);
string cmdText = "Insert into [Updates]([UpdateId],[Title,[Image])values(@updateId,@Title,@image)";
SqlCommand cmd = new SqlCommand(cmdText, con);
cmd.CommandType = CommandType.Text;
if (timage.HasFile.ToString() =="") //your file selection control
imgname = " ";
if (timage.HasFile.ToString() != null)
imgname = Request.Files.FileName.Substring(Request.Files.FileName.LastIndexOf("\\") + 1);
string extension = imgname.Remove(0, imgname.IndexOf('.'));
if (extension == ".jpg" || extension == ".jpeg" || extension == ".png"||extension==".bmp")
Request.Files.SaveAs(Server.MapPath("//Image\\" + imgname));
Label11.Text = "Invalid format of image.plase choose another format";
cmd.Parameters.Add("@updateId", System.Data.SqlDbType.VarChar).Value = uid.Text;
cmd.Parameters.Add("@Title", System.Data.SqlDbType.VarChar).Value = title.Text;
cmd.Parameters.Add("@content", cmd.Parameters.Add("@image", System.Data.SqlDbType.NVarChar).Value = imgname;
int result = cmd.ExecuteNonQuery();
// Retrieving image
string content = "select * from updates ";
command = new SqlCommand(content, con);
SqlDataReader mydatareader = command.ExecuteReader();
string path = "..Image" + "/" + mydatareader["Image"].ToString();
string filename = System.IO.Path.GetFileName(path);
May 26, 2011 07:06 AM|shahed.kazi|LINK
Usually, I store images in file system in folders with folder names as the ids in database. For example, if id is 5, i would store images in /images/f/ folder.
May 26, 2011 07:30 AM|Nandip Makwana|LINK
If you are planning to store image in filesystem, Then check out following article and do not forget to implement the security as described in article...