为什么不能我的代码将文件保存到C盘?(Why can't my code save file

2019-11-04 02:59发布

我救了我的形象到位于项目根目录中的文件夹SiteImages但我想将它放在我的C盘上,并要保存和访问图片来自那里,即C:/ SiteImages但我想不出

编号:(上传)

string fileName = Path.GetFileName(FileUpload1.FileName);
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/SiteImages/") + fileName);

编号:(访问)

string FilePath = new Uri(Server.MapPath("~/SiteImages/")).AbsoluteUri;

请帮助,使其内的C盘工作

更新:问题是现在的GridView从采摘C驱动器的图片。

旧:

<img src='../SiteImages/<%# Eval("PersonalInfoEmployeePicture") %>' width="20" height="20" onmouseover="ShowFull(this)" onmouseout="ShowActual(this)" />

Answer 1:

它应该是简单,因为它是正确的?

string fileName = Path.GetFileName(FileUpload1.FileName);
FileUpload1.PostedFile.SaveAs("C:\\SiteImages\\" + fileName);

string FilePath = "C:\\SiteImages\\" + fileName;

更新:正如你所说,你希望它是访问绝对URI,在IIS中创建一个虚拟目录指向SiteImages文件夹中的C :. 这样,您可以使用Server.MapPath函数映射路径到您指定的文件夹。



Answer 2:

只是删除开始..在图像源

<img src='/SiteImages/<%# Eval("PersonalInfoEmployeePicture") %>' width="20" height="20" onmouseover="ShowFull(this)" onmouseout="ShowActual(this)" />

如果你还在使用下面的代码保存上传的图片

FileUpload1.PostedFile.SaveAs(Server.MapPath("~/SiteImages/") + fileName);


文章来源: Why can't my code save files to C drive?