C# 已创建目录,但文件未保存在文件夹中

C# 已创建目录,但文件未保存在文件夹中,c#,asp.net,C#,Asp.net,在这里,userwise创建了一个文件夹,我想将文件保存在user文件夹中。 在创建文件夹之前,Im成功,但在创建文件夹之后,当我要保存文件时,它将不成功 错误显示 SaveAs方法配置为需要根路径 我的代码 protected void Page_Load(object sender, EventArgs e) { foreach (string s in Request.Files) { HttpPostedFile file = Request.Files

在这里,userwise创建了一个文件夹,我想将文件保存在user文件夹中。 在创建文件夹之前,Im成功,但在创建文件夹之后,当我要保存文件时,它将不成功

错误显示

SaveAs方法配置为需要根路径

我的代码

 protected void Page_Load(object sender, EventArgs e)
{
    foreach (string s in Request.Files)
    {
        HttpPostedFile file = Request.Files[s];
        int fileSizeInBytes = file.ContentLength;
        string fileName = file.FileName;
        string fileExtension = "";

        if (!string.IsNullOrEmpty(fileName))
            fileExtension = Path.GetExtension(fileName);
            Guid UserGUID = (Guid)Membership.GetUser().ProviderUserKey;

            string UserFolderPath = "~/UploadedFiles/" + UserGUID;
            System.IO.Directory.CreateDirectory(Server.MapPath(UserFolderPath));

        //Upto this line it's OK.Below this,Not save the files inside the directory
       //I have no idea below 2 lines are correct or not

            string savedFileName = Path.Combine(UserFolderPath);
            file.SaveAs(UserFolderPath);
    }
}

您需要将文件夹与文件名合并,以获得发送到
SaveAs
的最终路径:

string savedFileName = Path.Combine(Server.MapPath(UserFolderPath), fileName);
file.SaveAs(savedFileName);