C# 如何将文件保存到上级文件夹?
服务器中的文件夹结构如下所示:C# 如何将文件保存到上级文件夹?,c#,webforms,directory,C#,Webforms,Directory,服务器中的文件夹结构如下所示: www.example.com 图像 web文件 这里是所有用于web的文件 index.html example.html 我的代码在web文件文件夹中。要在web文件中保存文件,我可以使用server.MapPath(“~\\folder”)但如何将文件保存到位于上层的images文件夹中,该文件夹与www.example.com下的web文件位于同一层 新学员,请引导..如何 server.MapPath("~/images/myfile.jpg
- www.example.com
- 图像
- web文件
- 这里是所有用于web的文件
- index.html
- example.html
- 图像
server.MapPath(“~\\folder”)
但如何将文件保存到位于上层的images文件夹中,该文件夹与www.example.com下的web文件位于同一层 新学员,请引导..如何
server.MapPath("~/images/myfile.jpg");
MapPath方法将指定路径映射到物理路径 这是给你的一些建议
<%
response.write(Server.MapPath("test.asp") & "<br />")
response.write(Server.MapPath("script/test.asp") & "<br />")
response.write(Server.MapPath("/script/test.asp") & "<br />")
response.write(Server.MapPath("\script") & "<br />")
response.write(Server.MapPath("/") & "<br />")
response.write(Server.MapPath("\") & "<br />")
%>
Output:
c:\inetpub\wwwroot\script\test.asp
c:\inetpub\wwwroot\script\script\test.asp
c:\inetpub\wwwroot\script\test.asp
c:\inetpub\wwwroot\script
c:\inetpub\wwwroot
c:\inetpub\wwwroot
或
我想他的意思是文件夹在根目录之上……在web.config中添加文件夹路径并将文件保存在该路径中。很简单。@codingkiwi.com是的,我正在尝试将文件保存到应用程序根文件夹上方的文件夹中。这将仅将文件保存到
web文件
directory。图像文件夹和web文件文件夹处于同一级别。保存文件的代码位于web文件文件夹中。所以如果使用这个代码server.mappath(“~\\myfile.jpg”)代码>,它只能将文件保存在web文件夹中。请将images文件夹指定为iis中的虚拟目录,以便在代码中,它的行为与web文件夹中的行为相同,但实际上它将位于您现在拥有的结构中。看,我试过了,但只能保存在应用程序文件夹中。我正在尝试将文件保存在应用程序根目录之上Server.MapPath(“..\”)
或(Server.MapPath(“..”)
给我一个错误不能使用前导..退出顶部目录上方。
response.write(Server.MapPath("../"))
response.write(Server.MapPath("..\"))