hhh
hhh

Reputation: 51

access images outside the web path

How can i display images that are saved outside the the WebSite folder. Any example would be greatly appreciated?

Upvotes: 1

Views: 527

Answers (2)

x2.
x2.

Reputation: 9668

Create page which will take id or image name as get parameter, then load image and writes it to response.

Response.Clear();
Response.ClearHeaders();
Response.ContentType = "image/jpeg";
Bitmap test = new Bitmap("fileName.jpg");
test.Save(Response.OutputStream, ImageFormat.Jpeg);

Upvotes: 0

John Boker
John Boker

Reputation: 83709

To do this you could write a handler that would know the location of your files then use the Response.WriteFile http://msdn.microsoft.com/en-us/library/system.web.httpresponse.writefile.aspx to get the file and write it to the output stream.

You would need to set the content type first so the browser knows what you're doing.

Similar to what is being done in this example: http://www.dotnetperls.com/response-writefile

Upvotes: 2

Related Questions