Need help with ASP and File Access

D

David Elliott

As I am new to ASP.Net, I am looking for some insight on how to solve this issue.

I have a main page that loads a custom control. The custom control has a DataList
object. The DataSource is set to an array of objects which are filename, for right
now. This will change to a File ID, Directory ID, and Scaling Properties for displaying
thumbnails of pictures.

I am receiving an error -- exception.Message = "Access to the path is denied."
I am sure that this is because it is an ASP.Net project and I am trying to access
the file system.

Any information, pseudo design / object relationship / code as to how to correct
this, would be appreciated..

I am planning on caching the pictures on a directory by directory basis which I was
planning on doing in the ImageFeed class.

Here is the code I currently am using:

Thanks,
Dave


<asp:Image id=Image runat="server" ImageUrl='<%#
"ImageFeed.aspx?imageName=" +
DataBinder.Eval(Container.DataItem, "FileName") %>'>
</asp:Image>


public class ImageFeed : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
string imageName = Request.QueryString["imageName"];
if (imageName != null)
{
stringdirectory = this.MapPath(@"..\Pictures");
stringfilename = directory + @"\" + imageName;

try
{
FileStream fs = new FileStream(filename, FileMode.Open);
byte[] data = new byte[fs.Length];
fs.Read(data, 0, data.Length);
fs.Close();

Response.BinaryWrite(data);
}
catch (Exception ex)
{
string s = ex.Message;
}
}
}
}
 
K

Kevin Spencer

Hi Dave,

It's not aproblem with your code. It's a permissions issue. ASP.Net by
default runs under an account (ASPNET) with very limited permissions. You
have to either grant that user permission to do the file ops you want to do,
or run ASP.Net under a user account with the proper permissions.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top