简体   繁体   English

ASP.NET文件上传不起作用

[英]Asp.net file upload not working

I am trying to upload file but getting an error The given path's format is not supported." 我正在尝试上传文件,但出现错误。不支持给定路径的格式。”

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

and also tried the following but still not working. 并且尝试了以下方法,但仍然无法正常工作。

filePosted.SaveAs( storageLocation ,+ newFile);

How can I solve the problem? 我该如何解决这个问题?

If newFile is a file name like newFile="myfile.rar"; 如果newFile是文件名,例如newFile="myfile.rar"; then use this: 然后使用这个:

filePosted.SaveAs(storageLocation + newFile);

It seems you have an extra , near the + . 看来你有一个额外的,附近的+

But if newFile is empty like the question's code, you should set a value before .SaveAs : 但是,如果newFile像问题的代码一样为空,则应在.SaveAs之前设置一个值:

newFile = filePosted.FileName;

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

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

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