Export Report directly to Word in C# in CRM 2011 RRS feed

  • Question

  • Hi,

    I want to save a certain CRM Report directly in Word.

    I've gotten pretty far thanks to a post I found (an example) but I got stuck.

    The report (standard Quote report) is running fine and is correctly saved as a word document.

    The only issue I have is that I need to filter it to a certain Quote only instead of all of them.

    This is done via de parameter P1 and CRM takes care of the rest with CRMAF_table functionality.

    He is using /CRMReports/rsviewer/reportviewer.aspx and /Reserved.ReportViewerWebControl.axd, but I can't find any good docs on them.

    I've tried adding a records parameter and a P1 parameter to the call to reportviewer.aspx.

    But he doesn't filter and always exports all quotes.

    I also would like to know how this setup avoids the use of passing userid and organisationid as parameter.

    The call to reportviewer.aspx is to get a context and controlid and the heavy lifting is done in the axd file.

    Can this be run from an IFD setup or not?

    Here is my code that I'm using for the moment.

    If you could just point me in the right direction and maybe some links with details concerning the parameters of reportviewer.aspx and Reserved.ReportViewerWebControl.axd.

    A real life example would be even nicer offcourse ;-)

    static void Main(string[] args)
                String ReportName = "Tente Quote";
                Guid ReportId = new Guid("66D67DD7-B7D0-E111-9935-005056B20024");
                Guid QuoteId = new Guid("45C07E1D-AABB-E111-AEC0-005056B20024");
                String ReportViewerPath = "http://srv-nlam-d-036.thinq.ms:5555/TenteInt/CRMReports/rsviewer/reportviewer.aspx";
                String OrganizationName = "TenteInt";
                String ServerUrl = "http://srv-nlam-d-036.thinq.ms:5555/TenteInt";
                XMLHTTP30 reportRequest = new XMLHTTP30();
                reportRequest.open("POST", ReportViewerPath, false);
                reportRequest.setRequestHeader("Accept", "*/*");
                reportRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

                String CallingParameters = "id=%7B" + ReportId.ToString() + "%7D&uniquename=" + OrganizationName + "&iscustomreport=true&reportnameonsrs=&reportName=" + ReportName + "&isScheduledReport=false&P1=%7B" + QuoteId.ToString() + "%7D";
                var x = reportRequest.responseText.IndexOf("ReportSession=");
                var ret = new List<String>();
                ret.Add(reportRequest.responseText.Substring(x + 14, reportRequest.responseText.IndexOf("&", x) - (x + 14))); //the session id
                x = reportRequest.responseText.IndexOf("ControlID=");
                ret.Add(reportRequest.responseText.Substring(x + 10, reportRequest.responseText.IndexOf("&", x) - (x + 10))); //the control id

                XMLHTTP30 retrieveEntityReq = new XMLHTTP30();

                var pth = ServerUrl + "/Reserved.ReportViewerWebControl.axd?ReportSession=" + ret[0] + "&Culture=1033&CultureOverrides=True&UICulture=1033&UICultureOverrides=True&ReportStack=1&ControlID=" + ret[1] + "&OpType=Export&FileName=Public&ContentDisposition=OnlyHtmlInline&Format=WORD";
                retrieveEntityReq.open("GET", pth, false);
                retrieveEntityReq.setRequestHeader("Accept", "*/*");



    Sven Peeters

    Wednesday, July 18, 2012 11:24 AM


All replies