none
Exporting rdlc report as .docx not working RRS feed

  • Question

  • I am using VS 2019 and attempting to export (render) an rdlc report as .docx. When I try to open it I get an error that the content is corrupt and unreadable. How to solve this? Here is my code:

    byte[] bytesret = ReportViewer1.LocalReport.Render("WORDOPENXML", null, out mimeType, out encoding, out fileNameExtension, out streamids, out warnings);

    Response.Buffer = false;
    Response.Clear();
    Response.ClearHeaders();
    Response.ClearContent();
    Response.ContentType = "application/ms-word"   //***Note: also tried mimeType 
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.AddHeader("content-disposition", "attachment; filename=" + fileName); //attachement;
    Response.BinaryWrite(bytesret); // create the file
    Response.Flush();

    Wednesday, January 15, 2020 9:23 PM

All replies

  • Hi,

    For the above code I found suspicious code here :

    Response.ContentType = "application/ms-word"   //***Note: also tried mimeType 
    


    contentType for docx should be  as:

    Response.ContenType=  "application/vnd.openxmlformats-officedocument.wordprocessingml.document"


    With given code block and error info, it hard to diagnose which part case this scene. I suggest to follow Export RDLC Report to Word programmatically in ASP.Net Which was a succeed project that made by other contributor.

    Regards,
    Lukas


    MSDN Community Support Please remember to click Mark as Answer; the responses that resolved your issue, and to click Unmark as Answer if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 16, 2020 3:20 AM
  • Unfortunately that did not work.

    The sample on the URL was for WORD (.doc) not .docx

    Thursday, January 16, 2020 1:41 PM
  • As the code I read in the article, I think it is for programmatic export generally we could do some investigation and choose few words to make it work.

    MSDN Community Support Please remember to click Mark as Answer; the responses that resolved your issue, and to click Unmark as Answer if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, January 24, 2020 2:53 AM