日期:2014-05-18  浏览次数:20824 次

简单问题,解决给分,也许你未曾遇到过的问题
DirectoryInfo   DiFile=new   DirectoryInfo(@Server.Mappath( "/image/upload "))
如上,在使用Server.Mappath的时候出错,因为要求DirectoryInfo的参数是这样的,例如C:\\Windows\\System而Server.Mappath得到的却是C:\Window\System使用转义字符后仍然不行,除非直接输入@ "C:\Windows\System "做为DirectoryInfo   的参数才可以,另MSDN中提到在VB中却要求是C:\Windows\System这样的,在C#中是C:\\Windows\\System这样的,请问,我想用C#解决,怎么办?
MSDN中的URL:lp://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.chs/cpref8/html/T_System_IO_DirectoryInfo.htm
谢谢

------解决方案--------------------
直接Server.Mappath( "/image/upload "))
不要加上@
做为字符串传进去会自动辨识,不会认成转义字符
------解决方案--------------------
Server.Mappath( "./image/upload "))

------解决方案--------------------
DirectoryInfo DiFile=new DirectoryInfo(Server.Mappath( "~/image/upload "))

DirectoryInfo DiFile=new DirectoryInfo(Server.Mappath( "image/upload "))

我确定上面两个在服务器不禁Server.Mappath()方法的情况下没有任何问题。

在禁Server.Mappath()方法的时候要Request.PhysicalApplicationPath属性来自己转化

LZ可以自己测试一下



------解决方案--------------------
try:

DirectoryInfo DiFile=new DirectoryInfo(Server.Mappath(@ "/image/upload "))