Forum Discussion
Required code to remove the reports present in Power BI Embedded Workspace
You can delete a report by deleting the associated dataset.
I've managed to do this by adding the following code to Program.cs of the Sample app :
I added this code to the switch :
case '8':
if (string.IsNullOrWhiteSpace(workspaceCollectionName))
{
Console.Write("Workspace Collection Name:");
workspaceCollectionName = Console.ReadLine();
Console.WriteLine();
}
if (string.IsNullOrWhiteSpace(workspaceId))
{
Console.Write("Workspace ID:");
workspaceId = Console.ReadLine();
Console.WriteLine();
}
var datasets = displayDatasets(workspaceCollectionName, workspaceId);
Console.WriteLine("Choose which dataset to delete :");
string datasetId = Console.ReadLine();
await DeletePbixFile(workspaceCollectionName, workspaceId, datasetId);
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("Report deleted successfully");
await Run();
break;I created two methods that are called in the process :
The first one returns all the datasets (with their names and their ID) :
static async Task<ODataResponseListDataset> displayDatasets(string workspaceCollectionName, string workspaceId)
{
// Create a dev token for deletion
var devToken = PowerBIToken.CreateDevToken(workspaceCollectionName, workspaceId);
using (var client = await CreateClient(devToken))
{
var datasets = client.Datasets.GetDatasets(workspaceCollectionName, workspaceId);
foreach (Dataset set in datasets.Value)
{
Console.WriteLine("Name : {0} : Id : {1}", set.Name, set.Id);
}
return datasets;
}
}The second one deletes the dataset that has the ID that is passed as parameter :
static async Task DeletePbixFile(string workspaceCollectionName, string workspaceId, string datasetId)
{
// Create a dev token for deletion
var devToken = PowerBIToken.CreateDevToken(workspaceCollectionName, workspaceId);
using (var client = await CreateClient(devToken))
{
var deletion = client.Datasets.DeleteDatasetById(workspaceCollectionName, workspaceId, datasetId);
}
}Simply press 8 when prompted for a choice by the console, and then copy and paste the dataset ID of the dataset you which to delete (along with the report that comes with it).
It does work on my side, but do not hesitate to ask questions if it doesn't on your side.
Cheers :smileyhappy:
Your article usefull for me. deleted the report file work fine but how to remove workspce ID?
thank you.
- Anonymous10 years agoNot applicable
karthikeyan I don't know if removing a workspace is possible. I tried to remove one but I didn't manage to do so :smileyfrustrated:
- karthikeyan10 years agoRegular Visitor
Anonymous Hi , thank you tired friend.