0

I am trying to embed a Power BI report into a Windows Forms App (.NET Framework).

As I did not find any useful tutorial to do that I did the following:

I added WebView2 to my WinForms App and when opening the corresponding form the user should see the URL https://app.powerbi.com/reportEmbed?reportId=... but without the necessarity to enter any credentials.

Would that be possible using a token obtained via service principal?

Clifford
  • 88,407
  • 13
  • 85
  • 165
Gardinero
  • 331
  • 2
  • 13
  • This may help you https://stackoverflow.com/questions/40039899/is-it-possible-to-embed-power-bi-into-desktop-application – Gokul Maha Jun 04 '20 at 05:56

1 Answers1

0

No, the embed URL is not enough to show the report. The Power BI JavaScript client does the heavy lifting for you when embedding, and in your case (simply navigating to the embed URL) it isn't involved. Embedding Basics wiki shows you some examples how to leverage it to embed Power BI elements:

// Get models. models contains enums that can be used.
var models = window['powerbi-client'].models;

var embedConfiguration = {
    type: 'report',
    id: '5dac7a4a-4452-46b3-99f6-a25915e0fe55',
    embedUrl: 'https://app.powerbi.com/reportEmbed',
    tokenType: models.TokenType.Aad,
    accessToken: 'e4...rf'
};

var $reportContainer = $('#reportContainer');
var report = powerbi.embed($reportContainer.get(0), embedConfiguration);

So you either need to include this code in an HTML file and show this file in the browser, or to inject and execute it in the browser using C# code in your app. A working WinForms app demonstrating various embedding methods (including Chromium) can be downloaded from here.

In embedConfiguration you define what and how to be embedded. Then embed method of the client should be called, passing the configuration and the element, where the Power BI element should be shown.

Prior embedding it, you must authenticate the user (or the application) and acquire an access token (passed in accessToken property of the configuration). The easiest way to do it is to use a library like ADAL (Azure Active Directory Authentication Libraries) and call some of the AcquireTokenAsync methods. You can take a look at Is there any way to embed power bi reports and dashboards in vb.net or C# desktop application with sql server 2008 database? question.

Andrey Nikolov
  • 12,967
  • 3
  • 20
  • 32