1

我使用以下代码将文件保存到服务器,但是当我想创建文件夹时说:“不支持 URI 格式”

//Save File
string folderPath = MapPath(@"Attachment\");
FileUpload1.SaveAs(folderPath + name);

//Directory
Directory.CreateDirectory(folderPath+@"\111");
4

1 回答 1

2

检查之前存在

string folderPath =Server.MapPath("Attachment");
if(!Directory.Exists(folderPath))
   Directory.CreateDirectory(folderPath);

边注:

当您更好地使用连接路径时Path.Combine

FileUpload1.SaveAs(Path.Combine(folderPath , name));

或尝试

Directory.CreateDirectory(new Uri(folderPath+@"\111").LocalPath);

因为您收到“不支持 URI 格式”错误消息

于 2013-06-09T10:35:28.410 回答