I recently wrote a piece of code like this:
protected void OpenImg_Click(object sender, EventArgs e)
{
int i = 0;
string PathToFolder = "C://LiveSite/img/XL/";
var dirInfo = new DirectoryInfo(PathToFolder);
string FileName = Variables.param + "XL.jpg";
var foundFiles = dirInfo.GetFiles(FileName);
if (foundFiles.Length == 1)
{
ClientScript.RegisterStartupScript(this.GetType(), "openFoundImage", "window.open('" + PathToFolder + foundFiles[i].Name + "');", true);
}
}
}
}
It pathed correctly but it didn't work because it was pulling off the c:// drive so I changed the location of the image to: http://www.companysite.com/img/XL/
instead. When I replace string PathToFolder = "C://LiveSite/img/XL/";
with http://www.companysite.com/img/XL/
I get the error "URI formats are not supported"
So then I changed my code to:
protected void OpenImg_Click(object sender, EventArgs e)
{
int i = 0;
string uriPath = "http://www.companysite.com/img/XL/";
string localPath = new Uri(uriPath).LocalPath;
string FileName = Variables.param + "XL.jpg";
var foundFiles = localPath.GetFiles(FileName); //ERROR
if (foundFiles.Length == 1)
{
ClientScript.RegisterStartupScript(this.GetType(), "openFoundImage", "window.open('" + uriPath + foundFiles[i].Name + "');", true);
}
}
}
}
Now I get an error from using .GetFiles - What am I suppose to use instead of GetFiles? and is my code correct to pull the image from the web? Any help would be appreciated.