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;
}
}
}
}
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;
}
}
}
}