c# - 从文件夹中检索图像文件并显示到图像控件中

标签 c# asp.net file-upload

我已经使用下面的代码将我的图像保存在源文件的文件夹中.. 现在我必须在我的表单上检索相同的已保存图像

string filename = Path.GetFileName(fileupload1.PostedFile.FileName);
    string strtemp = System.DateTime.Now.ToString("ddMMyyhhmmss_") + filename;
    fileupload1.SaveAs(Server.MapPath("Image/" + strtemp));

那么我应该如何为我的图像控件提供路径 我已经尝试过类似的方法来获取文件和文件夹的路径,但我无法将图像从中提取到我的图像文件夹中

Image2.ImageUrl = (Server.MapPath("Image/" + strtemp));

最佳答案

像这样使用它:

Image2.ImageUrl = "~/Image/" + strtemp;

Server.MapPath 用于获取服务器资源的物理路径。您需要它来执行保存文件等操作。但是您的物理路径在网络上无效。您应该使用虚拟路径来指定 url。

关于c# - 从文件夹中检索图像文件并显示到图像控件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12459101/

相关文章:

javascript - 发布加载事件 Fullcalendar.io

php - 在 PHP 中上传时 $_FILES 为空

c# - 逐字节比较文件还是读取所有字节?

c# - 修改 string.Substring

c# - winforms 面板作为幻灯片?

php - 如何在 CakePHP 3 中使用 : Upload multiple images to server and save each image in database using cakephp 3

html - 如何在不将图像文件上传到服务器的情况下在浏览器中显示图像预览?

c# while 中的两个语句

c# - 带和不带 .aspx 扩展名的链接

asp.net - 是什么限制了我的 ASP.NET 应用程序可以与 Web 服务建立的同时连接数?