Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
When run throw code excel file gets generated but when deployed on server file does not get generated on the specified path but folder are created,stored procedure also returns data .... please help


DataTable _dt = MyData.GetDataSet(spName, para, 0).Tables[0];

if (_dt.Rows.Count > 0)
{
FileName = "//"+FileName+".xls";

rep_doc.Load(FilePath);
rep_doc.Refresh();
rep_doc.SetDataSource(_dt);
rep_doc.SetParameterValue("FromDate", txtFromDate.Text.Trim());
rep_doc.SetParameterValue("ToDate", txtToDate.Text.Trim());

string FinalPath = path + FileName;

rep_doc.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.Excel, FinalPath);
Posted
Updated 22-Jun-15 4:18am
v2

1 solution

Your code is running on the server. You are exporting the report to a file on the server.

If you want the Excel file to be saved on the client, then you have to write the file to the Response. The user will then be able to choose where to save it.

Rather than using ExportToDisk, use the ExportToHttpResponse method[^]:
C#
if (_dt.Rows.Count > 0)
{
    FileName = FileName + ".xls";
    
    rep_doc.Load(FilePath);
    rep_doc.Refresh();
    rep_doc.SetDataSource(_dt);
    rep_doc.SetParameterValue("FromDate", txtFromDate.Text.Trim());
    rep_doc.SetParameterValue("ToDate", txtToDate.Text.Trim());
    
    rep_doc.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.Excel, Response, true, FileName);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900