cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Want to add Export Power BI Report Feature in my application where in embed the report

Hello,

I embedded the power Bi report into our application, now i want to add export feature in to it.
Like when we see reports on https://app.powerbi.com  there is a bar on top of the report, where there is an option to export report into power point, pdf or print. Same feature i want to add into my application where i embedded the power BI report.
Can any help me in this ?
i searched alot, i found about exportToFile Api feature. But i want to add the same export feature into my app.

please help me in this.


Thanks,

Saad Ashraf

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Community Champion
Community Champion

Re: Want to add Export Power BI Report Feature in my application where in embed the report

You will have to implement the asynchronous process described in the documentation.  Your app needs to call the API with the export request, receive the job ID, then your app needs to poll the API with the job ID for the render status, and once rendering is complete, your app can then download the resulting blob and offer it to the app users for their download etc.

 

 

View solution in original post

Highlighted
Community Champion
Community Champion

Re: Want to add Export Power BI Report Feature in my application where in embed the report

6 REPLIES 6
Highlighted
Community Champion
Community Champion

Re: Want to add Export Power BI Report Feature in my application where in embed the report

You will have to implement the asynchronous process described in the documentation.  Your app needs to call the API with the export request, receive the job ID, then your app needs to poll the API with the job ID for the render status, and once rendering is complete, your app can then download the resulting blob and offer it to the app users for their download etc.

 

 

View solution in original post

Highlighted
Frequent Visitor

Re: Want to add Export Power BI Report Feature in my application where in embed the report

Thanks for responding Ibendlin. I really appreciate that.

Can you please tell me which documentation you are reffering here for asynchronous process ?

Highlighted
Community Champion
Community Champion

Re: Want to add Export Power BI Report Feature in my application where in embed the report

Highlighted
Frequent Visitor

Re: Want to add Export Power BI Report Feature in my application where in embed the report

Hi Ibendlin,

By using the referred document, i tried to export a power bi report from my application using this code.

 

var powerBIReportExportConfiguration = new PowerBIReportExportConfiguration
{
Settings = new ExportReportSettings
{
Locale = "en-us",
},
Pages = pageNames?.Select(pn => new ExportReportPage(pageName = pn)).ToList(),
};
var exportRequest = new ExportReportRequest
{
Format = format,
PowerBIReportConfiguration = powerBIReportExportConfiguration,
};

 

var url = XXX;
var content = new Dictionary<string, string>();
content["grant_type"] = "XXX";
content["resource"] = "XXX";
content["username"] = XXX;
content["password"] = XXX;
content["client_id"] = XXX;

var response = await APIHelper.MakeAsyncRequest(url, content);
var tokenresult = response.Content.ReadAsStringAsync().Result;
var OAuthResultModel = JsonConvert.DeserializeObject<OAuthResultModel>(tokenresult);
var authenticationResult = OAuthResultModel;

var credentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");
var client = new PowerBIClient(credentials);
var reportsResult = await client.Reports.ExportToFileInGroupAsync(GroupID, ReportID, exportRequest);

While executing the last line, code break and through an exception, i.e.:

 

{"Operation returned an invalid status code 'Forbidden"}


 

Highlighted
Community Champion
Community Champion

Re: Want to add Export Power BI Report Feature in my application where in embed the report

Highlighted
Frequent Visitor

Re: Want to add Export Power BI Report Feature in my application where in embed the report

After testing it out in the sandbox, I fix few thing in my code and now it is executing completely.
Here is the code , which i did.
public async Task<ExportedFile> ExportPowerBIReport(Guid ReportID, Guid GroupID, FileFormat format, int pollingtimeOutInMinutes, CancellationToken token, IList<string> pageNames = null)
{
try
{
var exportId = await PostExportRequest(ReportID, GroupID, format, pageNames);
var export = await PollExportRequest(ReportID, GroupID, exportId);
if (export == null || export.Status != ExportState.Succeeded)
{
// Error, failure in exporting the report
return null;
}
return await GetExportedFile(ReportID, GroupID, export);
}
catch(Exception ex)
{
// Error handling
throw ex;
}
}

 

 

but the problem i am facing right now is after executing the last line, i.e.
           return await GetExportedFile(ReportID, GroupID, export);

it takes me to the browser with a error pop-up. just "error" written on it.. and the report didn't downloaded.

My report is consist of 3 pages, so do i am referring the right document ? or i should go with this one ?https://docs.microsoft.com/en-us/power-bi/developer/embedded/export-paginated-report

 

 

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Upcoming Events

Upcoming Events

Wondering what events you could join or have an event to promote yourself? Check out our Upcoming Events.

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

We are thrilled to announce we will begin running a monthly webinar series named Power BI Dev Camp.