Skip to main content

IEditableDashboardStorage.AddDashboard(XDocument, String) Method

Adds a new dashboard to the current IEditableDashboardStorage.

Namespace: DevExpress.DashboardWeb

Assembly: DevExpress.Dashboard.v24.1.Web.dll

NuGet Package: DevExpress.Web.Dashboard.Common

Declaration

string AddDashboard(
    XDocument dashboard,
    string dashboardName
)

Parameters

Name Type Description
dashboard XDocument

A XDocument object that is the XML definition of the dashboard to be added.

dashboardName String

A String value that specifies the dashboard name.

Returns

Type Description
String

A String that is the identifier of the newly added dashboard.

Remarks

Implement the IEditableDashboardStorage.AddDashboard method to save a dashboard to the current IDashboardStorage.

Example

This example shows how to create custom dashboard storage in an ASP.NET Core application and to store dashboards in a database. The AddDashboard method is used to save a dashboard definition and its caption to the data storage. The method returns the ID of the new saved dashboard.

View Example: ASP.NET Core

public string AddDashboard(XDocument document, string dashboardName) {
    using (SqlConnection connection = new SqlConnection(connectionString)) {
        connection.Open();
        MemoryStream stream = new MemoryStream();
        document.Save(stream);
        stream.Position = 0;

        SqlCommand InsertCommand = new SqlCommand(
            "INSERT INTO Dashboards (Dashboard, Caption) " +
            "output INSERTED.ID " +
            "VALUES (@Dashboard, @Caption)");
        InsertCommand.Parameters.Add("Caption", SqlDbType.NVarChar).Value = dashboardName;
        InsertCommand.Parameters.Add("Dashboard", SqlDbType.VarBinary).Value = stream.ToArray();
        InsertCommand.Connection = connection;
        string ID = InsertCommand.ExecuteScalar().ToString();
        connection.Close();
        return ID;
    }
}

The following examples are based on different platforms and show how to create a custom dashboard storage to load and save dashboards to a database:

View Example: ASP.NET Core View Example: ASP.NET MVC View Example: ASP.NET Web Forms

See Also