您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

用于 .NET 的 Power BI Embedded 库Power BI Embedded libraries for .NET

Power BI 是基于云的业务分析服务,可提供最关键业务数据的单一视图。Power BI is a cloud-based business analytics service that gives you a single view of your most critical business data.

若要详细了解如何在 .NET 中使用 Power BI,请参阅 Power BI 的嵌入功能To learn more about using Power BI with .NET, see Embedding with Power BI.

客户端库Client library

使用客户端库来连接 Power BI API,以访问数据集和报表并与其交互。Use the client library to connect with Power BI APIs to access and interact with data sets and reports.

直接从 Visual Studio 包管理器控制台安装 NuGet 包Install the NuGet package directly from the Visual Studio Package Manager console.

Visual Studio 包管理器Visual Studio Package Manager

Install-Package Microsoft.PowerBI.Api

示例Example

以下示例检索并显示数据集和报表的列表。The following example retrieves and displays a list of datasets and reports.

/* Include these'using' directive:
using Microsoft.PowerBI.Api.V2;
using Microsoft.PowerBI.Api.V2.Models;
*/
using (PowerBIClient client = new PowerBIClient(new Uri(apiUrl), tokenCredentials))
{

    Console.WriteLine("\r*** DATASETS ***\r");

    // List of datasets in a group/app workspace
    ODataResponseListDataset datasetList = client.Datasets.GetDatasetsInGroup(groupId);

    foreach(Dataset ds in datasetList.Value)
    {
        Console.WriteLine(ds.Id + " | " + ds.Name);
    }

    Console.WriteLine("\r*** REPORTS ***\r");

    // List of reports in a group/app workspace
    ODataResponseListReport reportList = client.Reports.GetReportsInGroup(groupId);

    foreach (Report rpt in reportList.Value)
    {
        Console.WriteLine(rpt.Id + " | " + rpt.Name +  " | DatasetID = " + rpt.DatasetId);
    }
}

示例Samples

详细了解可在应用中使用的示例 .NET 代码Explore more sample .NET code you can use in your apps.