次の方法で共有


Installing and Localizing the Visual Studio 2005 Report Viewer Controls

While playing around with the report viewer controls and localization, I bumped into a few things I think are worth passing along.

In the "I should have known this in the first place" department, you must take steps to make sure the report viewer runs with the right culture settings in a web application.

While Report Manager automatically picks up the regional settings from the headers sent by your client (IE) and responds accordingly, ASP.NET does not.

So, you have to add a bit of code to make sure the web application changes culture based on information sent along by the browser. The following snippet in OnLoad() will work nicely:

        Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Request.UserLanguages[0]);

        Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(Request.UserLanguages[0]);

If you forget to do this (like I did) the report and viewer will never get localized, regardless of the regional settings on the client.

After that, you’ll get some of the report viewer localization functionality working. By that I mean you’ll see that the list of export formats is localized, etc. However, the labels on the report viewer toolbar (like “Export”, “Find | Next”, and “1 of X”) are not localized. To get THESE localized as well, you’ll need to install a language pack for the locale you’re interested in – ReportViewerLP.exe does this for you. I’m not clear where in Visual Studio 2005 and/or the Framework 2.0 SDK you’ll find these redists yet, but will post once I do.

After installing ReportViewerLP.exe for the specific locales you’re targeting, your report viewer controls will be happy and fully localized.

Oh, another question I’ve seen is “how do I install the report viewer controls to begin with?”. You’ll need to find and run the ReportViewer.exe redist, which is located in C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\v2.0\Bootstrapper\Packages\ReportViewer

Comments

  • Anonymous
    November 10, 2005
    Hi,
    Is any such option available with VS2003. Is there any other way to achieve globalization with Reports.
    I would like to have the Report static text and labels globalized, the strings being fetched from a text/xl file.
    your valuable comments are expected.
    Thanks
    Sree
  • Anonymous
    November 11, 2005
    Hi Sree --

    Unfortunately, no. You must do all the work yourself. Essentially, you'd need to save all the localized strings in a data store, then use the User!Language global to figure out the language that the user has set in Regional Settings. Next, you take this value (en-us, for example), and use it to retrieve the strings in question from SQL.

    I think this technique is documented in books online, and that there even is a sample report which demonstrates using it.
  • Anonymous
    November 11, 2005
    Here's the RDL for the report in question:

    <?xml version="1.0" encoding="utf-8"?>
    <Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2003/10/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
    <PageHeader>
    <ReportItems>
    <Textbox Name="textbox5">
    <Style>
    <PaddingLeft>2pt</PaddingLeft>
    <FontStyle>Italic</FontStyle>
    <TextAlign>Left</TextAlign>
    <PaddingBottom>2pt</PaddingBottom>
    <PaddingTop>2pt</PaddingTop>
    <PaddingRight>2pt</PaddingRight>
    </Style>
    <ZIndex>1</ZIndex>
    <Top>0.63492cm</Top>
    <rd:DefaultName>textbox5</rd:DefaultName>
    <Width>7.30159cm</Width>
    <CanGrow>true</CanGrow>
    <Value>=Globals!ExecutionTime</Value>
    <Left>0.31746cm</Left>
    </Textbox>
    <Textbox Name="textbox4">
    <Style>
    <PaddingLeft>2pt</PaddingLeft>
    <TextAlign>Left</TextAlign>
    <PaddingBottom>2pt</PaddingBottom>
    <PaddingTop>2pt</PaddingTop>
    <PaddingRight>2pt</PaddingRight>
    <FontWeight>700</FontWeight>
    </Style>
    <rd:DefaultName>textbox4</rd:DefaultName>
    <Height>0.63492cm</Height>
    <Width>3.375in</Width>
    <CanGrow>true</CanGrow>
    <Value>PRODUCT MODEL LISTING </Value>
    <Left>0.125in</Left>
    </Textbox>
    </ReportItems>
    <PrintOnLastPage>true</PrintOnLastPage>
    <PrintOnFirstPage>true</PrintOnFirstPage>
    <Style />
    <Height>0.5in</Height>
    </PageHeader>
    <RightMargin>1in</RightMargin>
    <Body>
    <ReportItems>
    <List Name="list1">
    <Style />
    <Height>1.5in</Height>
    <Top>0.125in</Top>
    <Width>6in</Width>
    <DataSetName>Product_Model_Details</DataSetName>
    <ReportItems>
    <Rectangle Name="rectangle2">
    <Top>0.125in</Top>
    <ReportItems>
    <Textbox Name="Name">
    <Style>
    <PaddingLeft>2pt</PaddingLeft>
    <TextAlign>Left</TextAlign>
    <PaddingBottom>2pt</PaddingBottom>
    <PaddingTop>2pt</PaddingTop>
    <PaddingRight>2pt</PaddingRight>
    </Style>
    <ZIndex>5</ZIndex>
    <Top>0.125in</Top>
    <rd:DefaultName>Name</rd:DefaultName>
    <Height>0.25in</Height>
    <Width>2.625in</Width>
    <CanGrow>true</CanGrow>
    <Value>=Fields!Name.Value</Value>
    <Left>1.375in</Left>
    </Textbox>
    <Textbox Name="Description">
    <Style>
    <PaddingLeft>2pt</PaddingLeft>
    <TextAlign>Left</TextAlign>
    <PaddingBottom>2pt</PaddingBottom>
    <PaddingTop>2pt</PaddingTop>
    <PaddingRight>2pt</PaddingRight>
    </Style>
    <ZIndex>4</ZIndex>
    <Top>0.5in</Top>
    <rd:DefaultName>Description</rd:DefaultName>
    <Height>0.25in</Height>
    <CanGrow>true</CanGrow>
    <Value>=Fields!Description.Value</Value>
    <Left>1.375in</Left>
    </Textbox>
    <Textbox Name="textbox2">
    <Style>
    <PaddingLeft>2pt</PaddingLeft>
    <PaddingBottom>2pt</PaddingBottom>
    <PaddingTop>2pt</PaddingTop>
    <PaddingRight>2pt</PaddingRight>
    <FontWeight>700</FontWeight>
    </Style>
    <ZIndex>3</ZIndex>
    <Top>0.5in</Top>
    <Height>0.25in</Height>
    <Width>1.125in</Width>
    <CanGrow>true</CanGrow>
    <Value>Description:</Value>
    <Left>0.125in</Left>
    </Textbox>
    <Textbox Name="textbox1">
    <Style>
    <PaddingLeft>2pt</PaddingLeft>
    <PaddingBottom>2pt</PaddingBottom>
    <PaddingTop>2pt</PaddingTop>
    <PaddingRight>2pt</PaddingRight>
    <FontWeight>700</FontWeight>
    </Style>
    <ZIndex>2</ZIndex>
    <Top>0.125in</Top>
    <rd:DefaultName>textbox1</rd:DefaultName>
    <Height>0.25in</Height>
    <Width>1.125in</Width>
    <CanGrow>true</CanGrow>
    <Value>Model Name:</Value>
    <Left>0.125in</Left>
    </Textbox>
    <Textbox Name="textbox3">
    <Style>
    <PaddingLeft>2pt</PaddingLeft>
    <PaddingBottom>2pt</PaddingBottom>
    <PaddingTop>2pt</PaddingTop>
    <PaddingRight>2pt</PaddingRight>
    <FontWeight>700</FontWeight>
    </Style>
    <ZIndex>1</ZIndex>
    <Top>0.875in</Top>
    <Height>0.25in</Height>
    <Width>1.125in</Width>
    <CanGrow>true</CanGrow>
    <Value>Total Sales:</Value>
    <Left>0.125in</Left>
    </Textbox>
    <Textbox Name="TotalSales">
    <Style>
    <PaddingLeft>2pt</PaddingLeft>
    <Format>c</Format>
    <TextAlign>Left</TextAlign>
    <PaddingBottom>2pt</PaddingBottom>
    <PaddingTop>2pt</PaddingTop>
    <PaddingRight>2pt</PaddingRight>
    </Style>
    <Top>0.875in</Top>
    <rd:DefaultName>TotalSales</rd:DefaultName>
    <Height>0.25in</Height>
    <Width>1in</Width>
    <CanGrow>true</CanGrow>
    <Value>=Fields!TotalSales.Value</Value>
    <Left>1.375in</Left>
    </Textbox>
    </ReportItems>
    <Height>1.25in</Height>
    <Style>
    <BorderStyle>
    <Default>Solid</Default>
    </BorderStyle>
    </Style>
    <Left>0.125in</Left>
    </Rectangle>
    </ReportItems>
    <Left>0.125in</Left>
    </List>
    </ReportItems>
    <Style />
    <Height>1.75in</Height>
    </Body>
    <TopMargin>1in</TopMargin>
    <DataSources>
    <DataSource Name="AdventureWorks2000">
    <rd:DataSourceID>a213e8f2-a1b5-4ae0-b171-0b19cd05efe9</rd:DataSourceID>
    <DataSourceReference>AdventureWorks2000</DataSourceReference>
    </DataSource>
    </DataSources>
    <Width>6.5in</Width>
    <DataSets>
    <DataSet Name="Product_Model_Details">
    <Fields>
    <Field Name="ProductModelID">
    <DataField>ProductModelID</DataField>
    <rd:TypeName>System.Int32</rd:TypeName>
    </Field>
    <Field Name="Name">
    <DataField>Name</DataField>
    <rd:TypeName>System.String</rd:TypeName>
    </Field>
    <Field Name="LocaleID">
    <DataField>LocaleID</DataField>
    <rd:TypeName>System.String</rd:TypeName>
    </Field>
    <Field Name="Description">
    <DataField>Description</DataField>
    <rd:TypeName>System.String</rd:TypeName>
    </Field>
    <Field Name="TotalSales">
    <DataField>TotalSales</DataField>
    <rd:TypeName>System.Double</rd:TypeName>
    </Field>
    </Fields>
    <Query>
    <DataSourceName>AdventureWorks2000</DataSourceName>
    <CommandText>SELECT ProductModel.ProductModelID, ProductModel.Name, ProductModelXProductDescriptionXLocale.LocaleID, ProductDescription.Description, sum(LineTotal) as TotalSales
    FROM Product inner join SalesOrderDetail on Product.ProductID = SalesOrderDetail.ProductID
    INNER JOIN ProductModel on ProductModel.ProductModelID = Product.ProductModelID
    INNER JOIN ProductModelXProductDescriptionXLocale on ProductModel.ProductModelID = ProductModelXProductDescriptionXLocale.ProductModelID
    INNER JOIN ProductDescription on ProductDescription.ProductDescriptionID = ProductModelXProductDescriptionXLocale.ProductDescriptionID
    WHERE ProductModelXProductDescriptionXLocale.LocaleID = @Locale
    GROUP BY ProductModel.ProductModelID, ProductModel.Name, ProductModelXProductDescriptionXLocale.LocaleID, ProductDescription.Description
    ORDER BY ProductModel.ProductModelID, ProductModel.Name</CommandText>
    <QueryParameters>
    <QueryParameter Name="@Locale"&gt;
    <Value>=Parameters!Locale.Value</Value>
    </QueryParameter>
    </QueryParameters>
    <rd:UseGenericDesigner>true</rd:UseGenericDesigner>
    </Query>
    </DataSet>
    </DataSets>
    <LeftMargin>1in</LeftMargin>
    <rd:SnapToGrid>true</rd:SnapToGrid>
    <rd:DrawGrid>true</rd:DrawGrid>
    <rd:ReportID>4addff13-2a50-42ef-b489-edbcfcc6adbe</rd:ReportID>
    <BottomMargin>1in</BottomMargin>
    <ReportParameters>
    <ReportParameter Name="Locale">
    <DataType>String</DataType>
    <Nullable>true</Nullable>
    <DefaultValue>
    <Values>
    <Value>=left(User!Language,2)</Value>
    </Values>
    </DefaultValue>
    <AllowBlank>true</AllowBlank>
    </ReportParameter>
    </ReportParameters>
    </Report>
  • Anonymous
    June 07, 2006
    A while ago, I wrote a bit about how to localize the Report Viewer controls. You can find that information...
  • Anonymous
    November 10, 2006
    Somthing Strange,Well I have installed evrything as described (french version), and I am using:       Thread.CurrentThread.CurrentCulture = New CultureInfo("fr-FR")       Thread.CurrentThread.CurrentUICulture = New CultureInfo("fr-FR")the parameter menu language has changed to french, the exprot button has become exporter (in french) but all the other (Find, Next, 1 of x, refresh and print are still in english)Any suggetion or help on this is appreciated.ThanksPaul
  • Anonymous
    May 29, 2007
    PingBack from http://www.bloginformatico.net/2007/05/29/localizzare-il-controllo-microsoft-reportviewer/
  • Anonymous
    December 04, 2007
    Hi all,     Thanks for your solutions, It's working.Regards,G.V.Senthilkumar.
  • Anonymous
    January 21, 2009
    PingBack from http://www.keyongtech.com/2197649-internationalization-support-in-ssrs-2005-a
  • Anonymous
    March 12, 2009
    OK, How do you get regional setting for a report that is embedded in an application not a web page.
  • Anonymous
    June 07, 2009
    PingBack from http://greenteafatburner.info/story.php?id=3744