none
Visual Studio 2012 use RDLC Stylesheet to generate RDLC file editable by Visual Studio 2012 Report Designer RRS feed

  • Question

  • I have a VS2012 WinForms project where I am dynamically building an RDLC file from a dataset and it kind of works... but the stylesheet file I am using is old and I need to find one that will work correctly.  It creates an RDLC file that I can open in the Visual Studio 2012 designer.. it asks me to upgrade the format to 2012.   Here is the strange part - after I let VS2012 upgrade the RDLC file and save it, The Visual Studio 2012 Report Viewer can't open the file.  It says it is corrupted.  If I just open the RDLC file right after using the old StyleSheet, the ReportViewer opens the report just fine...  I just can't edit it in VS2012.   It is really bazaar because while in the VS2012 Report Designer, I get no errors, the dataset shows up fine and everything looks perfect...  but when trying to open the actual RDLC file using the ReportViewer, I get an error:

    The report definition is not supported by this version of Reporting Services.  This could be the result of publishing a report definition of a later version of Reporting Services or that the report definition contains XML that is not well-formed or the XML is not valid based on the Report Definition schema.  Details '.' hexadecimal value 0x00 is an invalid character. Line 2, position 1. 

    I would like to know where the problem is so I can get this to work with VS2013 or VS2015... not sure what the error is referring to.  I got this stylesheet from a website no longer being maintained, but I'm not sure how to re-generate it for the latest version of Visual Studio.

    Here is the code:

        Friend Shared Function BuildRDLC(data As DataSet, name As String) As Boolean

            Try

                data.DataSetName = name  'Set the RDLC name and dataset name the same

                'Only pass a dataset with 1 table

                Dim physicalSchema As String = Application.StartupPath & "\Reports\" & name & ".schema"

                If IO.File.Exists(physicalSchema) Then

                    IO.File.Delete(physicalSchema)

                End If

                data.WriteXmlSchema(physicalSchema)

                Dim xmlDomScheuma As System.Xml.XmlDocument = New System.Xml.XmlDocument

                xmlDomScheuma.Load(physicalSchema)

                xmlDomScheuma.DocumentElement.SetAttribute("Name", name & "_Table")

                Dim physicalRDLC As String = Application.StartupPath & "\Reports\" & name & ".rdlc"

                Dim physicalXslt As String = Application.StartupPath & "\Reports\RDLCTemplate.xsl"

                If Not IO.File.Exists(physicalXslt) Then

                    MsgBox("Unable to find: " & physicalXslt & vbLf & vbLf & "Please contact the vendor for this file" _

                           , MsgBoxStyle.Critical, "Stylesheet not found")

                    Return False

                End If

                Dim xml As String = TransformXml(xmlDomScheuma.OuterXml, physicalXslt)

                Dim xmlDomRDLC As System.Xml.XmlDocument = New System.Xml.XmlDocument

                xmlDomRDLC.LoadXml(xml)

                xmlDomRDLC.Save(physicalRDLC)

                Return True

            Catch ex As Exception

                Return False

            End Try

        End Function

        Friend Shared Function TransformXml(xml As String, xslFile As String) As String

            Dim result As String = String.Empty

            Dim memory As System.IO.MemoryStream = New System.IO.MemoryStream(System.Text.Encoding.ASCII.GetBytes(xml))

            Dim transform As System.Xml.Xsl.XslCompiledTransform = New System.Xml.Xsl.XslCompiledTransform

            transform.Load(xslFile)

            Dim xpathDoc As System.Xml.XPath.XPathDocument = New System.Xml.XPath.XPathDocument(memory)

            Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder

            Dim sw As System.IO.StringWriter = New System.IO.StringWriter(sb)

            transform.Transform(xpathDoc, Nothing, sw)

            result = sb.ToString

            Return result

        End Function

    I will post the XSL file in a comment because it would not let me paste it here due to it's size.







    Monday, December 15, 2014 6:46 PM

All replies

  • Here is RDCTemplate.xsl:  (first half)

    <?xml version="1.0"?>

    <!-- Stylesheet for creating ReportViewer RDLC documents -->

    <xsl:stylesheet version="1.0"

      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

      xmlns:msxsl="urn:schemas-microsoft-com:xslt"

      xmlns:xs="http://www.w3.org/2001/XMLSchema"

      xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"

      xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner"  xmlns="http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition"

      >

     

     <xsl:variable name="mvarName" select="/xs:schema/@Name"/>

     <xsl:variable name="mvarFontSize">8pt</xsl:variable>

     <xsl:variable name="mvarFontWeight">500</xsl:variable>

     <xsl:variable name="mvarFontWeightBold">700</xsl:variable>

     <xsl:template match="/">

      <xsl:apply-templates select="/xs:schema/xs:element/xs:complexType/xs:choice/xs:element/xs:complexType/xs:sequence">

      </xsl:apply-templates>

     </xsl:template>

     <xsl:template match="xs:sequence">

      <Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner"xmlns="http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition">

       <BottomMargin>1in</BottomMargin>

       <RightMargin>1in</RightMargin>

       <LeftMargin>1in</LeftMargin>

       <TopMargin>1in</TopMargin>

       <InteractiveHeight>11in</InteractiveHeight>

       <InteractiveWidth>8.5in</InteractiveWidth>

       <Width>6.5in</Width>

       <Language>en-US</Language>

       <rd:DrawGrid>true</rd:DrawGrid>

       <rd:SnapToGrid>true</rd:SnapToGrid>

       <rd:ReportID>7358b654-3ca3-44a0-8677-efe0a55c7c45</rd:ReportID>

       

       <xsl:call-template name="BuildDataSource">

       </xsl:call-template>

       <xsl:call-template name="BuildDataSet">

       </xsl:call-template>

       <Body>

        <Height>0.50in</Height>

        <ReportItems>

         <Table Name="table1">

          <DataSetName><xsl:value-of select="$mvarName" /></DataSetName>

          <Top>0.5in</Top>

          <Height>0.50in</Height>

          <Header>

           <TableRows>

            <TableRow>

             <Height>0.25in</Height>

             <TableCells>

              <xsl:apply-templates select="xs:element" mode="HeaderTableCell">

              </xsl:apply-templates>

             </TableCells>

            </TableRow>

           </TableRows>

          </Header>

          <Details>

           <TableRows>

            <TableRow>

             <Height>0.25in</Height>

             <TableCells>

              <xsl:apply-templates select="xs:element" mode="DetailTableCell">

              </xsl:apply-templates>

     

             </TableCells>

            </TableRow>

           </TableRows>

          </Details>

          <TableColumns>

           <xsl:apply-templates select="xs:element" mode="TableColumn">

           </xsl:apply-templates>

          </TableColumns>

         </Table>

        </ReportItems>

       </Body>

      </Report>

     </xsl:template>

     <xsl:template name="BuildDataSource">

      <DataSources>

       <DataSource Name="DummyDataSource">

        <ConnectionProperties>

         <ConnectString/>

         <DataProvider>SQL</DataProvider>

        </ConnectionProperties>

        <rd:DataSourceID>84635ff8-d177-4a25-9aa5-5a921652c79c</rd:DataSourceID>

       </DataSource>

      </DataSources>

     </xsl:template>

     <xsl:template name="BuildDataSet">

      <DataSets>

       <DataSet Name="{$mvarName}">

        <Query>

         <rd:UseGenericDesigner>true</rd:UseGenericDesigner>

         <CommandText/>

         <DataSourceName>DummyDataSource</DataSourceName>

        </Query>

        <Fields>

         <xsl:apply-templates select="xs:element" mode="Field">

         </xsl:apply-templates>

        </Fields>

       </DataSet>

      </DataSets>

     </xsl:template>

     <xsl:template match="xs:element" mode="Field">

      <xsl:variable name="varFieldName"

       <xsl:value-of select="@name" />

      </xsl:variable>

      <xsl:variable name="varDataType">

       <xsl:choose>

        <xsl:when test="@type='xs:int'">System.Int32</xsl:when>

        <xsl:when test="@type='xs:string'">System.String</xsl:when>

        <xsl:when test="@type='xs:dateTime'">System.DateTime</xsl:when>

        <xsl:when test="@type='xs:boolean'">System.Boolean</xsl:when>

       </xsl:choose>

      </xsl:variable>

      <Field Name="{$varFieldName}">

       <rd:TypeName><xsl:value-of select="$varDataType"/></rd:TypeName>

       <DataField><xsl:value-of select="$varFieldName"/></DataField>

      </Field>

     </xsl:template>

     <xsl:template match="xs:element" mode="HeaderTableCell">

      <xsl:variable name="varFieldName"

       <xsl:value-of select="@name" />

      </xsl:variable>


    Monday, December 15, 2014 6:47 PM
  • Here is the second half of the Stylesheet:

      <TableCell>

       <ReportItems>

        <Textbox Name="textbox{position()}">

         <rd:DefaultName>textbox<xsl:value-of select="position()"/>

         </rd:DefaultName>

         <Value><xsl:value-of select="$varFieldName"/></Value>

         <CanGrow>true</CanGrow>

         <ZIndex>7</ZIndex>

         <Style>

          <TextAlign>Center</TextAlign>

          <PaddingLeft>2pt</PaddingLeft>

          <PaddingBottom>2pt</PaddingBottom>

          <PaddingRight>2pt</PaddingRight>

          <PaddingTop>2pt</PaddingTop>

          <FontSize><xsl:value-of select="$mvarFontSize"/></FontSize

          <FontWeight><xsl:value-of select="$mvarFontWeightBold"/></FontWeight

          <BackgroundColor>#000000</BackgroundColor

          <Color>#ffffff</Color>

          <BorderColor>

           <Default>#ffffff</Default>

          </BorderColor>

          <BorderStyle>

           <Default>Solid</Default>

          </BorderStyle>

         </Style>

        </Textbox>

       </ReportItems>

      </TableCell>

     </xsl:template>

     <xsl:template match="xs:element" mode="DetailTableCell">

      <xsl:variable name="varFieldName"

       <xsl:value-of select="@name" />

      </xsl:variable>

      

      <TableCell>

       <ReportItems>

        <Textbox Name="{$varFieldName}">

         <rd:DefaultName><xsl:value-of select="$varFieldName"/></rd:DefaultName>

         <Value>=Fields!<xsl:value-of select="$varFieldName"/>.Value</Value>

         <CanGrow>true</CanGrow>

         <ZIndex>7</ZIndex>

         <Style>

          <TextAlign>Left</TextAlign>

          <PaddingLeft>2pt</PaddingLeft>

          <PaddingBottom>2pt</PaddingBottom>

          <PaddingRight>2pt</PaddingRight>

          <PaddingTop>2pt</PaddingTop>

          <FontSize><xsl:value-of select="$mvarFontSize"/></FontSize

          <FontWeight><xsl:value-of select="$mvarFontWeight"/></FontWeight

          <BackgroundColor>#e0e0e0</BackgroundColor

          <Color>#000000</Color

          <BorderColor>

           <Default>#ffffff</Default

          </BorderColor>

          <BorderStyle>

            <Default>Solid</Default>

          </BorderStyle>

         </Style>

        </Textbox>

       </ReportItems>

      </TableCell>

     </xsl:template>

     <xsl:template match="xs:element" mode="TableColumn">

      <TableColumn>

       <Width>0.75in</Width>

      </TableColumn>

     </xsl:template>

     <xsl:template name="replace-string">

      <xsl:param name="text"/>

      <xsl:param name="from"/>

      <xsl:param name="to"/>

      <xsl:choose>

       <xsl:when test="contains($text, $from)">

        <xsl:variable name="before" select="substring-before($text, $from)"/>

        <xsl:variable name="after" select="substring-after($text, $from)"/>

        <xsl:variable name="prefix" select="concat($before, $to)"/>

        <xsl:value-of select="$before"/>

        <xsl:value-of select="$to"/>

        <xsl:call-template name="replace-string">

         <xsl:with-param name="text" select="$after"/>

         <xsl:with-param name="from" select="$from"/>

         <xsl:with-param name="to" select="$to"/>

        </xsl:call-template>

       </xsl:when>

       <xsl:otherwise>

        <xsl:value-of select="$text"/>

       </xsl:otherwise>

      </xsl:choose>

     </xsl:template>

    </xsl:stylesheet>


    Monday, December 15, 2014 6:48 PM
  • Hi jdressing1,

    I am moving your thread into the Visual Studio Report Controls Forum for dedicated support. Thanks for your understanding.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, December 16, 2014 6:43 AM