我之前已经成功地使用 webimage 帮助程序上传了一个文件,但我现在正试图将它与创建一个目录结合起来,并且失败了。这是我的代码:
if(IsPost){
//Create Directory using PropertyID
var imageroot = Server.MapPath("~/Images/Property/");
var foldername = rPropertyId.ToString();
var path = Path.Combine(imageroot, foldername);
if(!Directory.Exists(path)){
Directory.CreateDirectory(path);
}
photo = WebImage.GetImageFromRequest();
if(photo != null){
MediumFileName = rPropertyId + "_" + gooid + "_" + "Medium";
imagePath = path + MediumFileName;
photo.Save(@"~\" + imagePath);}
}
首先,我创建一个名称为 propertyID 的目录。这工作正常。然后我尝试将新照片上传到该路径中,我收到一条错误消息,提示“不支持给定路径的格式”。
有任何想法吗?