【问题标题】:Unable to get a full name when i try to download a excel当我尝试下载 Excel 时无法获得全名
【发布时间】:2014-03-20 14:10:44
【问题描述】:

当我尝试下载具有全名的文件时,它无法下载。但是在一个参数中,我将参数作为文件名发送。文件路径是自动生成的。

下载文件名为:Update_4_Product(截图所示)

实际文件名是:Update_4_Product Details.xlsx

这是我的代码

    private void DownloadUploadDataTemplate(string fileName)
    {
        string Outgoingfile = fileName + ".xlsx";
        string targetDirectory = Path.GetDirectoryName(XTP.Caching.AppSettingCache.GalleryFilePath) + @"\" + this.TenantCode + "\\Files" + @"\" + Outgoingfile;
        System.IO.FileInfo file = new System.IO.FileInfo(targetDirectory);
        if (file.Exists)
        {
            Response.Clear();
            Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
            Response.AddHeader("Content-Length", file.Length.ToString());
            Response.ContentType = "application/vnd.ms-excel";
            Response.WriteFile(file.FullName);
            HttpContext.Current.ApplicationInstance.CompleteRequest();
        }
        else
        {
            this.MessageLabel.Text = "File Not Found";
        }
    }

谁能告诉我我的代码有什么问题。

【问题讨论】:

    标签: asp.net excel c#-4.0 download


    【解决方案1】:

    只需删除文件名中的空格。

    str = str.Replace(" ", "_");
    

    Update_4_Product_Details.xlsx 而不是Update_4_Product Details.xlsx

    它按预期工作。

    【讨论】:

      猜你喜欢
      • 2016-07-16
      • 1970-01-01
      • 2022-06-14
      • 2018-07-25
      • 2011-07-12
      • 2016-05-08
      • 2022-10-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多