This is a migrated thread and some comments may be shown as answers.

Using external style sheet in Telerik reporting when the aspx page hosting the Report viewer is not at the root level of the site

2 Answers 246 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Guillaume
Top achievements
Rank 1
Guillaume asked on 17 Jul 2012, 04:28 AM

Hello,

I am using C# and Asp.NET in the issue described below.

I have a Website which I access to using the following Url: http://localhost:8349.

This Website has the following folder at its root level: Reporting
Reporting folder hosts another folder: Reports
Finally, Reports also hosts a folder: Styles

The Styles folder contains one file called Style.xml. This file is a Stylesheet that I got by exporting the Style set on a previously existing report. Its build action is set to Content and its Copy to Output Directory is set to Do not copy.

Inside the Reports folder, I have a Telerik report called Report1.cs. It has a single textbox with its StyleName property set to a value from within the Style.xml. The report itself has one External StyleSheet that corresponds to the file in the Styles folder. The Kind is set to Relative.

At the root level of my Website I have an aspx page called MyReport.aspx. It contains a single report viewer. In the Page_Load method of the page, I have the following code:

Report1 report = new Report1();
ReportManagementViewer.Report = report;

All namespaces are correctly added.

There is no other files or folders except those created by default by Visual Studio. I am using all default settings for the files, project and the solution as well as Visual Studio.

When I open the report in the designer mode, the style I want is correctly applied. When I run the Website and access to MyReport.aspx (http://localhost:8349/MyReport.aspx), the style is also correctly applied.

Now, in the Reporting folder I create a new aspx Webform called MyReport.aspx. This page also has a single report viewer as its only component and its Page_Load method contains the same code as above. All namespaces are correctly added.

When I open the report in designer mode, my style is still correctly applied. But when I access this new page (http://localhost:8349/Reporting/MyReport.aspx) the style is ignored. In Visual Studio, if I open Report1.Designer.cs and I change the following line:

this.ExternalStyleSheets.Add(new Telerik.Reporting.Drawing.ExternalStyleSheet("Reporting\\Reports\\Styles\\Style.xml"));

to this

this.ExternalStyleSheets.Add(new Telerik.Reporting.Drawing.ExternalStyleSheet("..\\Reporting\\Reports\\Styles\\Style.xml"));

I can correctly see my style applied when I access the report from the second Url. But when I want to access the report from the designer in Visual Studio it crashed with the following error message:

"The service Telerik.Reporting.Design.Interfaces.IRootDesignerPresenter already exists in the service container. Parameter name: serviceType"

If I try to update the same line of code to this:

if (!DesignMode)
{
    this.ExternalStyleSheets.Add(new Telerik.Reporting.Drawing.ExternalStyleSheet("..\\Reporting\\Reports\\Styles\\Style.xml"));
}
else
{
    this.ExternalStyleSheets.Add(new Telerik.Reporting.Drawing.ExternalStyleSheet("Reporting\\Reports\\Styles\\Style.xml"));
}

it crashes with the following error message:

"The designer cannot process the code at line 64: [the whole code above] The code within the method 'InitializeComponent' is generated by the designer and should not be manually modified. Please remove any changes and try opening the designer again".

If I run the application and try to access the page hosting my report in the sub-folder, the style is correctly applied.

I've also tried to prefix the path to the Style in the designer.cs with ~ or use the Style as a resource but in both cases it ends up working whether in the designer or in the live application but never for both at the same time.

My question:

How can I access to a report with an External Style Sheet both in the live application and in the designer when the ASPX page hosting the report viewer is not located at the root level of my Website?

Thanks for your help

Additional information:
- Visual Studio 2010 SP1 and .NET 4
- Windows XP SP3. Regional settings; English (United States). Same for the language.
- Version of Telerik Reporting: 6.0.12.215. This is also the version of Telerik reporting used by the original report from which the style has been extracted.
- Browser: Internet Explorer 8.0.6001.18702
- I don't use any external plugin except Telerik Reporting and RadControls for Silverlight (not used in this project). ReSharper is installed on my machine but not activated. No NuGet or other stuffs like that. No customization of any kind in Visual Studio.

2 Answers, 1 is accepted

Sort by
0
Accepted
Hrisi
Telerik team
answered on 19 Jul 2012, 03:17 PM
Hi Guillaume,

Use this code but place it in the constructor of the report after the call of the InitializeComponent() method.
if (!DesignMode)
{
    this.ExternalStyleSheets.Add(new Telerik.Reporting.Drawing.ExternalStyleSheet("..\\Reporting\\Reports\\Styles\\Style.xml"));
}

Hope this helps.

All the best,
Hrisi
the Telerik team

BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

0
Guillaume
Top achievements
Rank 1
answered on 20 Jul 2012, 02:00 AM
Hello Hrisi,

Thanks for your answer, it's working great!
Tags
General Discussions
Asked by
Guillaume
Top achievements
Rank 1
Answers by
Hrisi
Telerik team
Guillaume
Top achievements
Rank 1
Share this question
or