Hi there I am writing ASP.NET app
I want to access gif images stored in Images folder which is in turn stored in Project folder. See my Solution Explorer.

In GetImage.ashx (see solution explorer), I am unable to get images using this:

System.IO.FileStream _FileStream = new System.IO.FileStream("~/Images/" + imageFileName + ".gif", System.IO.FileMode.Open, System.IO.FileAccess.Read);

It gives exception Couldd not find a part of path 'C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\~\Images\alien_tai_chi_md_wht.gif'.

Please help. Currently I am using full directory specification:
System.IO.FileStream _FileStream = new System.IO.FileStream(@"C:\Users\MAHESH\Desktop\s\ASPNETWebsites\WebDataDisplay\Images\"+imageFileName+".gif", System.IO.FileMode.Open, System.IO.FileAccess.Read);

Recommended Answers

All 2 Replies

What's the root folder for your web server? The path seems wrong.

use this will help you

System.IO.FileStream(server.MapPath("~/Images/" + imageFileName + ".gif",System.IO.FileMode.Open, System.IO.FileAccess.Read);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.