我知道这是一个菜鸟问题,以前有人问过,但是这里的其他答案对我来说并没有澄清。我正在上传文件,然后提供预览。我的上传按钮的点击事件是这样的:
protected void UploadFile (object sender, EventArgs e) {
string folderPath = Server.MapPath ("~/Uploads/");
// If folder does not exist, create it.
if (!Directory.Exists (folderPath))
Directory.CreateDirectory (folderPath);
//Save the File to the Directory (Folder).
FileUpload.SaveAs (folderPath + Path.GetFileName (FileUpload.FileName));
//Display the Picture in Image control.
imgItem.ImageUrl = folderPath + Path.GetFileName (FileUpload.FileName);
}
上传正常,但是图像控件(imgItem)不显示图片。当我跟踪它时,URL看起来很完美。网址是:
"C:\\MyStuff\\Source\\Inventory\\Inventory\\UserInterface\\Uploads\\sample.jpg"
应该可以。我到底在做什么错?
嗯,
“ C:\ MyStuff \ Source \ Inventory \ Inventory \ UserInterface \ Uploads \ sample.jpg”
实际上是文件路径,而不是URL。由于您使用的是“ URL”一词,因此我假设您正在构建一个网站。这意味着您需要一个正确的网址(例如http(s)://yourdomain.com/Source/Inventory/..../sample.jpg)