Skip to main content

XtraReport.StyleSheetPath Property

Gets or sets a path to the style sheet contained in a style sheet file.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v24.1.dll

NuGet Package: DevExpress.Reporting.Core

Declaration

[DefaultValue("")]
[SRCategory(ReportStringId.CatAppearance)]
public string StyleSheetPath { get; set; }

Property Value

Type Default Description
String String.Empty

A path to the style sheet file.

Remarks

You can use the StyleSheetPath property to change a report control’s style programmatically:

  • associate the report control with a style name;
  • add different styles with this name to style sheet files;
  • change the report’s StyleSheetPath property value in code depending on a parameter.

Refer to the Store Report Style Sheets topic for instructions on how to implement this task.

You can also use the StyleSheet property to assign a style sheet to a report. If you specify both the StyleSheet and StyleSheetPath properties, the styles loaded from a style sheet file have a higher priority than the styles that are defined in the report’s style sheet. This means that if the styles stored in the report have the same names as the styles loaded from a style sheet file, the styles in the file substitute their namesakes.

Note

The styles loaded from a file cannot be edited in a report.

Create a style sheet file in the StyleSheet Editor that is invoked for the XtraReport.StyleSheet property in the Report Designer.

You can assign both absolute and relative paths to the StyleSheetPath property.

An absolute path specifies a complete path to the style sheet file. If you move your application to another directory, you have to update the specified path.

A relative path refers to a location that is relative to the base directory. The following table details what folder you should take as the base directory.

Application in Visual Studio (Design Time or Runtime) Deployed Application
The application project’s directory The application’s directory

Perform the following steps before you deploy your application to provide relative path resolution.

Desktop

  • Set the style sheet file’s Copy to Output Directory property to Copy Always.
  • Set the style sheet file’s Build Action property to Content.
  • To specify image paths relative to another directory (not the application’s BaseDirectory), set the global DXResourceDirectory variable.

    // Set the resource directory to the Images folder within the user's profile.
    string dataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Images");
    AppDomain.CurrentDomain.SetData("DXResourceDirectory", dataPath);
    

ASP.NET Web Forms & MVC

  • Set the style sheet file’s Copy to Output Directory property to Copy Always.
  • Set the style sheet file’s Build Action property to Content.
  • Set directory access rules.

    • An application with Web Reporting controls
      Implement the following code in your application to allow access to the directory that contains style sheet files, since the Reporting controls provide access to URLs only.

      public class Global : System.Web.HttpApplication {
      
        protected void Application_Start(object sender, EventArgs e) {
            // Set access rules to data
            string dataPath = Server.MapPath("Resources");
            AccessSettings.ReportingSpecificResources.TrySetRules(DirectoryAccessRule.Allow(dataPath));
        }
        // ...
      }
      
    • Application prints or exports reports from code (does not include Web Reporting controls)
      You do not have to set directory access rules.

  • Set the global DXResourceDirectory variable.

    • An application with Web Reporting controls
      You do not have to set this variable. The reporting controls resolve relative paths relative to the application’s directory.
    • An application prints or exports reports from code (does not include Web Reporting controls)

      public class Global : System.Web.HttpApplication {
      
        protected void Application_Start(object sender, EventArgs e) {
            // Set the resource directory
            string contentPath = Server.MapPath("");
            AppDomain.CurrentDomain.SetData("DXResourceDirectory", contentPath);
        }
        // ...
      }
      

ASP.NET Core

  • Set the style sheet file’s Copy to Output Directory property to Copy Always.
  • Set the style sheet file’s Build Action property to Content.
  • Set directory access rules.

    • An application with Web Reporting controls
      Implement the following code in your application to allow access to the directory that contains style sheet files, since the Reporting controls provide access to URLs only.

      var app = builder.Build();
      
      // Set access rules to data
      string dataPath = System.IO.Path.Combine(contentPath, "Data");
      string dataPath2 = System.IO.Path.Combine(contentPath, "wwwroot\\Resources");
      AccessSettings.ReportingSpecificResources.TrySetRules(DirectoryAccessRule.Allow(dataPath, dataPath2));
      
      app.Run();
      
    • An application prints or exports reports from code (does not include Web Reporting controls)
      You do not have to set directory access rules.

  • Set the global DXResourceDirectory variable.

    • An application with Web Reporting controls
      You do not have to set this variable. The reporting controls resolve relative paths relative to the application’s directory.
    • An application prints or exports reports from code (does not include Web Reporting controls)

      var app = builder.Build();
      
      // Set the resource directory
      string contentPath = env.ContentRootPath;
      AppDomain.CurrentDomain.SetData("DXResourceDirectory", contentPath);
      
      app.Run();
      
See Also