in appx/Power BI Embedded/powerbi-sample-app/powerbi-sample-app/Controllers/DashboardController.cs [87:123]
public async Task<ActionResult> Upload(ReportUploadModel report)
{
string workspaceId = report.ReportCategory;
// See if we have a new workspace name
if (!String.IsNullOrWhiteSpace(report.NewReportCategory))
{
using (var client = new PowerBIReportClient(PowerBIToken.CreateProvisionToken(this.workspaceCollection), this.workspaceCollection, String.Empty))
{
var newWorkspaceResult = await client.Workspaces.PostWorkspaceAsync(this.workspaceCollection);
this.workspaces.Workspaces.Add(new ReportWorkspace
{
DisplayName = report.NewReportCategory,
WorkspaceId = newWorkspaceResult.WorkspaceId,
Reports = new List<Report>(),
});
workspaceId = newWorkspaceResult.WorkspaceId;
// Update web.config
var webConfig = WebConfigurationManager.OpenWebConfiguration("~");
webConfig.AppSettings.Settings["WorkspaceMappings"].Value = String.Join(";", this.workspaces.Workspaces
.Select(workspace => String.Format("{0}|{1}", workspace.WorkspaceId, workspace.DisplayName)));
webConfig.Save();
}
}
using (var client = new PowerBIReportClient(this.workspaceCollection, workspaceId))
{
var import = await client.Imports.PostImportWithFileAsync(this.workspaceCollection,
workspaceId,
report.PbixReport.InputStream,
report.ReportName);
import = await client.WaitForImportToComplete(import);
if (import.ImportState == PowerBIReportClient.StateSucceeded)
{
return RedirectToAction("Report", new { workspaceId = workspaceId, reportId = import.Reports.First().Id });
}
}
return RedirectToAction("Index");
}