本文介绍了获取错误为“不是虚拟虚拟路径”同时保存图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 < 表格 id = form1 runat = server > < div > < ; asp:按钮 ID = Button1 runat = server onclick = Button1_Click 文字 = 按钮 / > < br / > < asp:FileUpload ID = filUpload runat = server / > < / div > < /表格 > protected void Button1_Click(object sender,EventArgs e) { string savepath =; var directoryInfo = new DirectoryInfo(C:\\Users \\viki \\Documents \\Visual Studio 2008 \\WebSites\\WebSite3); if(directoryInfo.Exists) { string a =NewFolder1; directoryInfo.CreateSubdirectory(a); savepath = a; } if(filUpload.PostedFile!= null) { //SaveFile(filUpload.PostedFile); HttpFileCollection colFiles = HttpContext.Current.Request.Files; HttpPostedFile objCurrentFile = colFiles.Get(0); string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(objCurrentFile.FileName); string fileExtension = Path.GetExtension(objCurrentFile.FileName); filUpload.PostedFile.SaveAs(Server.MapPath(directoryInfo +\\+ savepath)+ fileNameWithoutExtension + fileExtension); } } 我收到保存为line.it的错误说该路径不是虚拟路径。 帮我完成此文件上传通过创建一个新的动态文件夹来处理。 提前谢谢.. 解决方案 在网络应用程序中你无法访问以在本地计算机上保存文件。您只能将文件保存在Web应用程序的子文件夹中。这是有效路径的示例:〜\ MyFolder并且表示来自我的Web应用程序根目录的文件夹MyFoloder。 if (filUpload.PostedFile!= null ) { string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filUpload.PostedFile.FileName); string fileExtension = Path.GetExtension(filUpload.PostedFile.FileName); filUpload.PostedFile.SaveAs(Server.MapPath(savepath + / + fileNameWithoutExtension + fileExtension)); } 工作正常..感谢大家,你的想法让它解决了。再次感谢你。 <form id="form1" runat="server"> <div> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> <br /> <asp:FileUpload ID="filUpload" runat="server" /> </div> </form>protected void Button1_Click(object sender, EventArgs e) { string savepath=""; var directoryInfo = new DirectoryInfo("C:\\Users\\viki\\Documents\\Visual Studio 2008\\WebSites\\WebSite3"); if (directoryInfo.Exists) { string a = "NewFolder1"; directoryInfo.CreateSubdirectory(a); savepath = a; } if (filUpload.PostedFile != null) { //SaveFile(filUpload.PostedFile); HttpFileCollection colFiles = HttpContext.Current.Request.Files; HttpPostedFile objCurrentFile = colFiles.Get(0); string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(objCurrentFile.FileName); string fileExtension = Path.GetExtension(objCurrentFile.FileName); filUpload.PostedFile.SaveAs(Server.MapPath(directoryInfo+"\\"+savepath)+ fileNameWithoutExtension + fileExtension); } }I'm getting the error in the save as line.it's saying that the path is not a vaild virtual path.Help me to complete this file upload process by creating a new dynamic folder.Thanks in advance.. 解决方案 In web application you have not access to save the file on your local computer. You can save the files only in subfolders of your web application. This is an example of valid path: "~\MyFolder" and means the folder ""MyFoloder" from my web application root.if (filUpload.PostedFile != null) { string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filUpload.PostedFile.FileName);string fileExtension = Path.GetExtension(filUpload.PostedFile.FileName);filUpload.PostedFile.SaveAs(Server.MapPath(savepath + "/" + fileNameWithoutExtension + fileExtension)); }It's working fine.. Thanks to everyone,your ideas made it to solve.Thank you Once again. 这篇关于获取错误为“不是虚拟虚拟路径”同时保存图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-15 08:44