上传的文件未保存到目录

时间:2016-11-14 20:17:04

标签: c# asp.net

我正在尝试使用devexpress上传文件保存为与标准asp.net上传器完全相同的功能,但我收到以下错误

  

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

UploadDirectory指的是网络配置中的虚拟目录设置,我通过该属性获取。

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

}

从上面调用以下保存的发布文件

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

1 个答案:

答案 0 :(得分:0)

我注意到很多文件操作方法和类在处理空间的方式上有所不同,有时候的方式也没有很好的记录。例如,我已经看到测试文件名中包含空格的文件是否成功但是打开文件没有成功的情况。

这只是一种预感,但似乎很可能。

相关问题