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
Resident Rockstar
Resident Rockstar

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
Resident Rockstar
Resident Rockstar

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

6 REPLIES 6
Highlighted
Resident Rockstar
Resident Rockstar

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
Resident Rockstar
Resident Rockstar

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
Resident Rockstar
Resident Rockstar

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
May 2020 Community Highlights

May 2020 Community Highlights

It’s time for another PBI Community recap!

Community Blog

Community Blog

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

Using the Community

Using the Community

Need help with the Power BI Community? Our 'Using the Community' support articles are a great place to start.

Galleries

Galleries

Looking for inspiration on how to present your data? Need instructional videos? Check out our Galleries!