无法在操作方法中添加response.write()

时间:2017-03-26 07:32:17

标签: c# asp.net-mvc

我试图下载批量Excel数据,所以我使用server.mappath()保存文件,但问题是文件被下载到特定文件夹但我没有在浏览器中获取下载文件。那么如何在ASP.NET MVC中添加response.write

调用CreateExcelDocument方法:

string worksheet_name = "RetailerReport.xls";
string MyDocumentsPath = System.Environment.GetFolderPath(
          Environment.SpecialFolder.MyDocuments);

CreateExcelFile.CreateExcelDocument(ds, MyDocumentsPath + "\\" + worksheet_name);

CreateExcelDocument方法:

public static bool CreateExcelDocument(DataSet ds, string excelFilename)
{
    try
    {

        using (SpreadsheetDocument document = SpreadsheetDocument.Create(
            excelFilename, SpreadsheetDocumentType.Workbook))
        {
            WriteExcelFile(ds, document);
        }
        Trace.WriteLine("Successfully created: " + excelFilename);
        return true;
    }
    catch (Exception ex)
    {
        Trace.WriteLine("Failed, exception thrown: " + ex.Message);
        return false;
    }
}

创建excel文件后,我想添加response.write

0 个答案:

没有答案