繁体   English   中英

ASP.NET文件上传不起作用

[英]Asp.net file upload not working

我正在尝试上传文件,但出现错误。不支持给定路径的格式。”

    string storageLocation = string.Empty;
    string newFile;

    switch (ddlDocType.SelectedItem.Text)
    {
        case "Letter":
            storageLocation = Server.MapPath("~/Documents/Letters/");
            break;

...

        if (filePosted.ContentLength > 0)
        {
                filePosted.SaveAs(Path.Combine( storageLocation , newFile));
        }

并且尝试了以下方法,但仍然无法正常工作。

filePosted.SaveAs( storageLocation ,+ newFile);

我该如何解决这个问题?

如果newFile是文件名,例如newFile="myfile.rar"; 然后使用这个:

filePosted.SaveAs(storageLocation + newFile);

看来你有一个额外的,附近的+

但是,如果newFile像问题的代码一样为空,则应在.SaveAs之前设置一个值:

newFile = filePosted.FileName;

您的变量newFile永远不会被赋值,因此Path.Combine()将失败。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM