Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

So I'm having some trouble displaying images from outside of the project folder...

I seem to be only able to access images within the "~" directory and subdirectories...

Say, if I want to access images from "E:/XYZ/11-01-01 New Year/" or something like that how may I do so?

Note: I set privileges on all folders and sub folders as Readable to "Everyone" so IIS/Visual Studio should be able to but isn't showing the images in the Image Control

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
111 views
Welcome To Ask or Share your Answers For Others

1 Answer

You should use an HttpHandler to show the images.

Googling for "httphandler images" turns up numerous examples on how to do this.

Instead of trying to link directly to you images, you would link to the handler with the querystring determining which image to show. eg

http://mysite.com/MyHandler.ashx?image=myimage.jpg

Here's a very basic sample (minus error handling etc)

using System.IO;
using System.Web;
public class MyImageHandler : IHttpHandler 
{
    public void ProcessRequest(System.Web.HttpContext ctx) 
    {

        string _Path;

        _Path = "E:\XYZ\11-01-01 New Year" + context.Request.QueryString["image"];

        ctx.Response.StatusCode = 200;
        ctx.Response.ContentType = "image/jpeg";
        ctx.Response.WriteFile(_Path);      
    }

    public bool IsReusable { get {return true; } }        
 }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...