使用上传文件控件时出现此错误“给定路径的格式 不受支持“。
if (FUFile.PostedFile.ContentLength != 0)
{
string tempVar = "~/res/Posts/" + FUFile.Value.ToString();
FUFile.PostedFile.SaveAs(Server.MapPath(tempVar));
ftier.Addpostfromfront(LoggedUserID, "4", txpost.Value, tempVar, DateTime.Now, DateTime.Now, false, false);
}
当我查看我的代码时:
答案 0 :(得分:0)
仅提取文件名后使用属性FileName
if (FUFile.PostedFile.ContentLength != 0)
{
string file = Path.GetFileName(FUFile.PostedFile.FileName);
string tempVar = Path.Combine("~/res/Posts/", file);
FUFile.PostedFile.SaveAs(Server.MapPath(tempVar));
ftier.Addpostfromfront(LoggedUserID, "4", txpost.Value, tempVar, DateTime.Now, DateTime.Now, false, false);
}