【问题标题】:Error The given path's format is not supported错误 不支持给定路径的格式
【发布时间】:2014-02-02 20:11:39
【问题描述】:

我在使用上传文件控制时遇到了这个错误“给定路径的格式 不支持”。

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);



        }

当我检查我的代码时:

【问题讨论】:

  • 你试过什么?屏幕截图中的错误很明显 - 您正在混合路径。

标签: c# asp.net


【解决方案1】:

仅提取文件名后使用属性 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);
    }

【讨论】:

    猜你喜欢
    • 2017-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-19
    • 2012-03-08
    • 2011-11-13
    • 2012-04-21
    相关资源
    最近更新 更多