How to export a report in microsoft power bi with asp net mvc 5

Introduction

ASP.NET is a popular programming language used for building web applications. In this article, we will explore how to export a report in Microsoft BI ASP.NET MVC 5.

Step 1: Install Power BI SDK

The first step is to install the Power BI SDK, which provides the necessary libraries and tools to work with Power BI in your ASP.NET MVC application. You can install the SDK using NuGet manager by running the following command in the Package Manager Console:

Install-Package Microsoft.PowerBI.Api

Step 2: Authenticate with Power BI

In to export a report, you need to authenticate with Power BI using your credentials. You can do this by an instance of the AuthenticationContext class and calling the AcquireTokenAsync . Here's an example:

string authorityUrl = "https://login.microsoftonline.com/common";
string resourceUrl = "https://analysis.windows.net/powerbi/api";
string clientId = "YourClientId";
string clientSecret = "YourClientSecret";

AuthenticationContext authenticationContext = new AuthenticationContext(authorityUrl);
ClientCredential clientCredential = new ClientCredential(clientId, clientSecret);

AuthenticationResult authenticationResult = await authenticationContext.AcquireTokenAsync(resourceUrl, clientCredential);

Step 3: Get Report and Export

Once you are , you can retrieve the report you want to export using the Power BI API. You can do this by creating an instance of the PowerBIClient class and calling the .GetReportInGroupAsync method. Here's an example:

string groupId = "YourGroupId";
string reportId = "YourReportId";

PowerBIClient powerBIClient = new PowerBIClient(authenticationResult.AccessToken);
Report report = await powerBIClient.Reports.GetReportInGroupAsync(groupId, reportId);

Once you have the report, you can export it in various formats such as PDF, PPTX, or PNG. You can do this by calling the Exports.ExportToFileAsync method. Here's an example:

string exportFormat = "PDF";
string exportFilePath = "C:\Reports\report.pdf";

ExportToFileRequest exportRequest = new ExportToFileRequest(exportFormat, exportFilePath);
Export export = await powerBIClient.Exports.ExportToFileAsync(groupId, reportId, exportRequest);

Make sure to the placeholders with your actual group ID, report ID, client ID, and client secret.

Conclusion

In this article, we have learned how to export a report in Microsoft Power BI using ASP.NET MVC 5. By following the steps outlined above, you can easily integrate Power BI functionality into your web application and provide users with the to export reports in various formats.

Rate this post

Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents