I am using VS 2010 for developing a web application. I am storing the uploaded images in physical path of the Server and also created virtual path in IIS 7.5 (the screenshot below).In Authorization,one Warning is displayed.For using the belo code I try to retrieve the image from the server but the image is not display.Where the problem, in virtual path or in the path mention in code ?

private void CallImage()
{
SqlConnection SqlCon = new SqlConnection(GetConnectionString());
SqlCon.Open();
string query = "SELECT Cmp_DocPath FROM Company_Info WHERE
Vendor_ID= '" + ddlVendorID.SelectedValue + "'";
SqlCommand SqlCmd = new SqlCommand(query, SqlCon);
SqlDataAdapter da = new SqlDataAdapter(SqlCmd);
DataTable dt = new DataTable();
da.Fill(dt);
string ImageName = Convert.ToString(dt.Rows[0][0].ToString());
Image1.ImageUrl = this.ResolveUrl("D:/Upload/Commerical Certificates/"+ImageName);
// Image1.ImageUrl = this.ResolveUrl("D:\\Upload\\Commerical Certificates\\"+ImageName);
// Image1.ImageUrl = this.ResolveUrl("~\\Upload\\Commerical Certificates\\"+ImageName);
SqlCon.Close();
}
You can’t reference a physical location to an image and expect it to work on a Web site. Store the paths to the images as virtual paths from the root of the site. For instance:
If your site root is at:
And your images are at:
Then your virtual paths int he database need to be:
Then you can set that as the ImageUrl property and no, you don’t need to resolve it (the Image control does that automatically).
My guess is that the reason you’re having this problem is because you are trying to reference images that are not within the Web site, which even if you get to work in your dev environment by giving access to NETWORK SERVICE, IIS_IUSRS, the second you move this application into a production environment, you are going to have problems. Not to mention that is a very poor way to do things in terms of security and modularity.