In the below code i have a image i have pass image url from codebehind but it is not displaying the image. The url location is C:\\Search\\Searchdoc\\Documents\\Desert.jpeg
public string strClientName = "Searchdoc";
public string strDocumentFolder = "Documents";
string Imgdocname = SearchDoc.DocumentName;
string fileExt = System.IO.Path.GetExtension(Imgdocname);
fileExt = fileExt.ToLower();
if (fileExt == ".jpeg" || fileExt == ".jpg")
{
docimg.Src = "~/" + Search+ "/" + strClientName + "/" + strDocumentFolder + "/" + Imgdocname;
docimg.Visible = true;
}
else
{
docimg.Src= "~/Search/Searchdoc/Documents/image.jpeg";
docimg.Visible = true;
}
Well for a start, you are using the ~
character which indicates the root directory of the application.
Since you are saying that the image is in C:\\Search\\Searchdoc\\Documents\\
then that won't be found, since your code is actually looking in projectRoot\\Search\\Searchdoc\\Documents
As for how to get this image to show in a webpage, it won't simply work for accessing it from the C drive. IIS will not serve images that aren't in the web site folder structure. I would suggest moving it into the website.
If you need to keep it stored in a folder outside your website, you would need to look at streaming it, or using a sort of proxy page. Have a look at the answer here: How to display image which is stored in local drive? to get an idea of the proxy method
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.