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的时候出错,因为要求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
谢谢
不要加上@
做为字符串传进去会自动辨识,不会认成转义字符
FileInfo[] FileDns = unhost.GetFiles("*.jpg");
其中Newpath="image/upload";
这个程序总是有问题,怎么搞?
你说的的确对,前提是Server.Mappath()中的参数是字符串,若改成已知变量就不行了,如str="image/upload";
DirectoryInfo unhost = new DirectoryInfo(Server.MapPath("image/upload"))这样没有问题;
若是
DirectoryInfo unhost = new DirectoryInfo(Server.MapPath(str))就出问题了,请指教.