1

I would like to display SSRS reports in my custom WebPart. I would also like to set the permissions to particular AD user for accessing those reports.

How can I do it programmatically?

1

You can use the Report Viewer Web Part to view reports that run on report server that is configured to run in SharePoint integrated mode. You can use the Web Part to display report definition (.rdl) files that you created in Report Builder or Report Designer and uploaded to a library. link: http://technet.microsoft.com/en-us/library/bb326362(v=sql.110).aspx

Here is my code block that adds the web part to the page. This code block exists in FeatureActivated:

Assembly currentAssembly = Assembly.GetExecutingAssembly();
string dwpStr = string.Empty;

try
{
    using (Stream resourceStream = currentAssembly.GetManifestResourceStream("Report.dwp"))
    {
        using (StreamReader sr = new StreamReader(resourceStream))
        {
            dwpStr = sr.ReadToEnd();
            dwpStr = string.Format(dwpStr, web.Url);
            sr.Close();
        }
        resourceStream.Close();
    }

    using (StringReader sr = new StringReader(dwpStr))
    {
        string err = string.Empty;
        System.Web.UI.WebControls.WebParts.WebPart wp = wpMan.ImportWebPart((XmlReader.Create(sr as TextReader)), out err); //Exception thrown from this line
        wpMan.AddWebPart(wp, "HeaderZone", 0);
    }
}
catch (Exception ex)
{
    //Log errors
}

Report.dwp is as follows:

<?xml version="1.0" encoding="utf-8"?>
<WebPart xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/WebPart/v2">
  <FrameType>None</FrameType>
  <Description>Use the Report Viewer to view reports running on a Reporting Services report server configured for SharePoint integration.</Description>
  <IsIncluded>true</IsIncluded>
  <ZoneID>HeaderZone</ZoneID>
  <PartOrder>0</PartOrder>
  <FrameState>Normal</FrameState>
  <Height>175px</Height>
  <Width />
  <AllowRemove>false</AllowRemove>
  <AllowZoneChange>false</AllowZoneChange>
  <AllowMinimize>false</AllowMinimize>
  <AllowConnect>false</AllowConnect>
  <AllowEdit>true</AllowEdit>
  <AllowHide>false</AllowHide>
  <IsVisible>true</IsVisible>
  <DetailLink />
  <HelpLink />
  <HelpMode>Modeless</HelpMode>
  <Dir>Default</Dir>
  <PartImageSmall />
  <MissingAssembly>Cannot import this Web Part.</MissingAssembly>
  <PartImageLarge>/_layouts/images/ReportServer/ReportWebPart.gif</PartImageLarge>
  <IsIncludedFilter />
  <_locDefinition>
    <_locTag d3p1:_loc="locData" xmlns:d3p1="http://schemas.microsoft.com/WebPart/v2">Title</_locTag>
    <_locTag d3p1:_loc="locData" xmlns:d3p1="http://schemas.microsoft.com/WebPart/v2">Description</_locTag>
  </_locDefinition>
  <Title d2p1:_locID="WP_ReportViewer_Title" xmlns:d2p1="http://schemas.microsoft.com/WebPart/v2">SQL Server Reporting Services Report Viewer</Title>
  <Assembly>Microsoft.ReportingServices.SharePoint.UI.WebParts, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91</Assembly>
  <TypeName>Microsoft.ReportingServices.SharePoint.UI.WebParts.ReportViewerWebPart</TypeName>
  <ReportPath xmlns="urn:schemas-microsoft-com:SqlServerReportViewer">{0}/Rrports/MyReport.rdl</ReportPath>
  <HyperlinkTarget xmlns="urn:schemas-microsoft-com:SqlServerReportViewer">_top</HyperlinkTarget>
  <AutoGenerateTitle xmlns="urn:schemas-microsoft-com:SqlServerReportViewer">false</AutoGenerateTitle>
  <AutoGenerateDetailLink xmlns="urn:schemas-microsoft-com:SqlServerReportViewer">false</AutoGenerateDetailLink>
  <AsyncRendering xmlns="urn:schemas-microsoft-com:SqlServerReportViewer">true</AsyncRendering>
  <ToolBarMode xmlns="urn:schemas-microsoft-com:SqlServerReportViewer">None</ToolBarMode>
  <DocumentMapMode xmlns="urn:schemas-microsoft-com:SqlServerReportViewer">Hidden</DocumentMapMode>
  <DocumentMapAreaWidth xmlns="urn:schemas-microsoft-com:SqlServerReportViewer">200px</DocumentMapAreaWidth>
  <PromptAreaMode xmlns="urn:schemas-microsoft-com:SqlServerReportViewer">Hidden</PromptAreaMode>
  <OverrideParameters xmlns="urn:schemas-microsoft-com:SqlServerReportViewer" />
  <Title xmlns="urn:schemas-microsoft-com:SqlServerReportViewer" />
</WebPart

link: https://go4answers.webhost4life.com/Example/spfeaturereceiver-creating-report-137235.aspx https://go4answers.webhost4life.com/SearchResult.aspx?q=display+ssrs+report+in+webpart+programmatically

I hope that will enough to implement your solution

  • Where should I need to put this Report.dwp file? – Sameer Vaghela Jul 7 '14 at 9:13
  • I'm not able to implement above code – Sameer Vaghela Jul 7 '14 at 12:04
0

SharePoint has Report Explorer and Report Viewer WebParts

Their are certain Requirements for using these WebParts. Installation and Configuration steps are described in below link

Please check here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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