这是我的代码:
我只使用一个简单的数据列表来显示图像表单文件夹......
单击数据列表中的损坏图像图标后显示错误找不到资源。
说明:HTTP 404。您要查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请查看以下 URL 并确保其拼写正确。
请求的 URL:/WebSite2/Images/Desert.jpg
protected void BindDataList()
{
DirectoryInfo dir = new DirectoryInfo(MapPath(@"~/Images/"+Model.Text+"/"));
FileInfo[] files = dir.GetFiles();
ArrayList listItems = new ArrayList();
foreach (FileInfo info in files)
{
listItems.Add(info);
}
DataList1.DataSource = listItems;
DataList1.DataBind();
}
protected void upload_Click(object sender, EventArgs e)
{
string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.SaveAs(Server.MapPath("Images/"+Model.Text+"/" + filename));
BindDataList();
}
protected void newfolder_Click(object sender, EventArgs e)
{
string NewDirectory = Server.MapPath("Images/"+Model.Text);
//New Directory Name in string variable
CreateDirectoryIfNotExists(NewDirectory);
//Calling the function to create new directory
}
private void CreateDirectoryIfNotExists(string NewDirectory)
{
try
{
// Checking the existance of directory
if (!Directory.Exists(NewDirectory))
{
//If No any such directory then creates the new one
Directory.CreateDirectory(NewDirectory);
Label1.Text = "Directory Created";
}
else
{
Label1.Text = "Directory Exist";
}
}
catch (IOException _err)
{
Label1.Text = _err.Message; ;
}
}