【发布时间】:2013-06-21 15:27:58
【问题描述】:
我最近写了一段这样的代码:
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);
}
}
}
}
它的路径正确,但它不起作用,因为它正在拉出 c:// 驱动器,所以我将图像的位置更改为:http://www.companysite.com/img/XL/。当我将 string PathToFolder = "C://LiveSite/img/XL/"; 替换为 http://www.companysite.com/img/XL/ 时,出现错误“不支持 URI 格式”
然后我将代码更改为:
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);
}
}
}
}
现在我在使用 .GetFiles 时遇到错误 - 我应该使用什么来代替 GetFiles?我的代码从网络上提取图像是否正确?任何帮助将不胜感激。
【问题讨论】: