Home > Net >  Asp.net export Word: click the export button into a blank page, also without a Word
Asp.net export Word: click the export button into a blank page, also without a Word

Time:11-20

After a fill data according to the document template format in the generated Word document download
Public Boolean ExportCustomsDocumentObject (Page Page, string filename, out string errormsg)
{
Boolean writeOk=true;
Byte [] allbytes=null;
Try
{
The string fileName=
HttpContext. Current. Server. MapPath (" ~/App_Code WebApiService/xxxTemplate docx ");
Allbytes=OutCountrySituationDocumentEngine. GetOutCountrySituationDocumentObjectBytes (fileName,
Int. Parse (cmdYear SelectedValue), int. J Parse (cmdQuarter. SelectedValue));
The Response. ClearHeaders ();
The Response. ClearContent ();
The Response. AppendHeader (" the content - disposition, "
"The attachment; Filename="+ HttpUtility UrlEncode (filename, Encoding UTF8));
The Response. The ContentType="application/ms - word";
The Response. BinaryWrite (allbytes);
The Response. The End ();
}
The catch (Exception e)
{

}

Errormsg="";
Return writeOk;
}
Problem description:
In vs can normal running and generated the Excel file and can be downloaded,
After deployment to iis, click the output button, a blank page (all other page),

CodePudding user response:

Add some log to see if allbytes access to the value (normal VS, should be normal),
OutCountrySituationDocumentEngine. GetOutCountrySituationDocumentObjectBytes this encapsulation methods whether to call the Office components, if any, also to install on the server version of Office accordingly

CodePudding user response:

Page. The Response. The Clear ()
The Response. The Expires=0
The Response. The Buffer=True
Page. The Response. AddHeader (" the content-type ", "application/msword")


Page. The Response. AddHeader (" the Content - the Disposition ", "legislation; Filename="& amp; Server. The UrlEncode (spath2))
Page. The Response. The WriteFile (spath2)

Page. The Response. The End ()

CodePudding user response:

The above code can run normally

CodePudding user response:

refer to the second floor fangma2001 Response:
Page. The Response. The Clear ()
The Response. The Expires=0
The Response. The Buffer=True
Page. The Response. AddHeader (" the content-type ", "application/msword")


Page. The Response. AddHeader (" the Content - the Disposition ", "legislation; Filename="& amp; Server. The UrlEncode (spath2))
Page. The Response. The WriteFile (spath2)

Page. The Response. The End ()

I solved, thank you
  • Related