1

I need the C# code to export the rdlc file to .docx. I have tried out the following code.But it does not work. Please help me with proper code.Thanks in advance

RvQpTemplate.LocalReport.SetParameters(new ReportParameter[] { 
             regulation, ExamName, SubjectName, SubjectCode,common });
var report = new LocalReport();
report.SetBasePermissionsForSandboxAppDomain(new PermissionSet(PermissionState.Unrestricted));

RvQpTemplate.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource());
RvQpTemplate.DataBind();

Byte[] mybytes = RvQpTemplate.LocalReport.Render("WORD", null,
                                    out extension, out encoding,
                                    out mimeType, out streams, out warnings);
Response.ClearHeaders();
Response.ClearContent();
Response.Buffer = true;
Response.Clear();
Response.ContentType = contentType;
Response.AddHeader("Content-Disposition", "attachment; filename="test.docx");
Response.BinaryWrite(mybytes);
Response.Flush();
Response.Close();
Response.End();
3
  • 1
    rdlc is a report definition. It makes no sense to export it to a document. Are you asking how to render a report as a Word document? What is the problem? Do you get an exception, no result, a mangled document? Dec 12, 2014 at 10:02
  • 'does not work' is not a technical description to work on to solve an issue...
    – Paolo
    Dec 12, 2014 at 10:19
  • you cannot simply create .docx files and expect them to open in Word.. you need to explicitly create them./.. do you need this ?? Dec 12, 2014 at 10:45

2 Answers 2

4

Use WORDOPENXML instead of WORD when you render the report. Also, this was discussed here: How do I export directly to a word document in report viewer

0
public FileResult File(string id, string expedicion, string nombre, string historia)
    {                                    
        ReportViewer ReportViewer1 = new ReportViewer();
        ReportViewer1.ProcessingMode = ProcessingMode.Local;
        ReportViewer1.LocalReport.ReportPath = 
        Server.MapPath("~/Reportes/Plantilla2.rdlc");

        ReportViewer1.ShowParameterPrompts = true;
        ReportParameter ID = new ReportParameter("ID", id);
        ReportParameter EXP = new ReportParameter("Exp", expedicion);
        ReportParameter Nombre = new ReportParameter("Nombre", nombre);
        ReportParameter Historia = new ReportParameter("Historia", historia);
        ReportParameter Sede = new ReportParameter("Sede", usuario.idnom);
        ReportViewer1.LocalReport.SetParameters(ID);
        ReportViewer1.LocalReport.SetParameters(EXP);
        ReportViewer1.LocalReport.SetParameters(Nombre);
        ReportViewer1.LocalReport.SetParameters(Historia);
        ReportViewer1.LocalReport.SetParameters(Sede);
        ReportViewer1.LocalReport.Refresh();


        byte[] streamBytes = null;
        string mimeType = "";
        string encoding = "";
        string filenameExtension = "";
        string[] streamids = null;
        Warning[] warnings = null;

        streamBytes = ReportViewer1.LocalReport.Render("WORD", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);
        return File(streamBytes, mimeType, "Report1.doc");
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.