I am trying to implement a server control that breaks a couple of files inside an ASP.NET site web directory. I am using VS Web Dev Express 2008 as my IDE. When I call HttpContext.Current.Request.ApplicationPathto get the path to the root website, so I can find these files, it returns C :. What the hell?
Absolute paths work fine, but I want me to be able to manage the server with a relative directory and just let it do that. What did I do wrong?
public String Target
{
get { return _target; }
set
{
if (value.StartsWith("~"))
{
_target = HttpContext.Current.Request.ApplicationPath +
value.Substring(1);
}
else
{
_target = value;
}
}
}
private String _target;
protected override void Render(HtmlTextWriter writer)
{
HtmlControl wrapper = new HtmlGenericControl("div");
int fileCount = 0;
try
{
DirectoryInfo dir = new DirectoryInfo(_target);
foreach (FileInfo f in dir.GetFiles())
{
fileCount++;
a = new HtmlAnchor();
a.Attributes.Add("href", f.FullName);
a.InnerHtml = f.Name;
wrapper.Controls.Add(a);
}
}
catch (IOException e)
{
throw e;
}
Controls.Add(wrapper);
base.Render(writer);
}
source
share