上传的文件没有保存到目录

本文关键字:保存 文件 | 更新日期: 2023-09-27 18:17:57

我试图上传一个文件使用devexpress保存为功能,其工作原理与标准asp.net上传器完全相同,但我得到以下错误

无法找到路径"C:'Projects'fhs'fhs'Uploads'documents'VX00150'Barry Allen'Aperture - Signature Template.docx"的一部分。

UploadDirectory是指在web配置中设置的一个虚拟目录,我通过该属性获得。

 string UploadDirectory = WebConfigurationManager.AppSettings["uploadDirectory"].ToString();

包含目录

<add key="uploadDirectory" value="~'Uploads'" />

但是对于我来说,我不明白为什么文件不保存到服务器

protected void UploadControl_FileUploadComplete(object sender, FileUploadCompleteEventArgs e)
{

        UploadControl.Enabled = false;
          string id = Request.QueryString["Case"];
        if (id != null)
        {
            CaseId = Guid.Parse(id);
            OpenCase = _dal.GetCaseById(Guid.Parse(id));
        }
        string PersonId = Session["CurrentPersonalMainID"].ToString();
        Personal = _dal.GetPersonalByPersonalId(new Guid(PersonId));
        e.CallbackData = SavePostedFile(e.UploadedFile, OpenCase.CaseReference, Personal.firstName, Personal.lastName);
}

下面保存的postdfile从上面调用

public  string SavePostedFile(UploadedFile uploadedFile,string IVACaseRef, string firstName ,string lastName)
    {
        try
        {
if (!uploadedFile.IsValid)
            return string.Empty;
        string fileName = uploadedFile.FileName;
        FileInfo fileInfo = new FileInfo(uploadedFile.FileName);
        string fullFileName = CombinePath(fileName);
        string docsPath = UploadDirectory +  @"documents'" + IVACaseRef + @"'" + firstName + " " +
                          lastName + @"'";
        string resFileName =docsPath + fileInfo.Name;
        bool exists = System.IO.Directory.Exists(resFileName);
        if (!exists)
            System.IO.Directory.CreateDirectory(docsPath);
        uploadedFile.SaveAs(Server.MapPath(resFileName), true);
        System.Net.Mail.Attachment attachment;
        attachment = new System.Net.Mail.Attachment(resFileName.ToString());
        // we need to reget this as issue with postback and the fileuplaod
        FormsIdentity _identity = (FormsIdentity)Context.User.Identity;
        _identity = (FormsIdentity)Context.User.Identity;


        return fileName;
    }
    catch (Exception ex)
    {
        string inner = string.Empty;
        if (ex.InnerException != null)
        {
            inner = ex.InnerException.ToString();
        }
        //     logger.Error("Error in GetNotificationById function aperturenetdal " + ex.ToString() + " " + inner);
        return "";

上传的文件没有保存到目录

我注意到许多文件操作方法和类在处理空格的方式上有所不同,有时在处理空格的方式上没有很好的记录。例如,我看到过这样的情况:测试文件名中是否存在一个带有空格的文件,但打开它却没有成功。