Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
saadashraf
Helper I
Helper I

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
lbendlin
Super User
Super User

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

6 REPLIES 6
lbendlin
Super User
Super User

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.

 

 

Thanks for responding Ibendlin. I really appreciate that.

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

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"}


 

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.