Bitzsoft.Integrations.CloudDrive.Microsoft365
1.0.0-alpha.8
This is a prerelease version of Bitzsoft.Integrations.CloudDrive.Microsoft365.
dotnet add package Bitzsoft.Integrations.CloudDrive.Microsoft365 --version 1.0.0-alpha.8
NuGet\Install-Package Bitzsoft.Integrations.CloudDrive.Microsoft365 -Version 1.0.0-alpha.8
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Bitzsoft.Integrations.CloudDrive.Microsoft365" Version="1.0.0-alpha.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bitzsoft.Integrations.CloudDrive.Microsoft365" Version="1.0.0-alpha.8" />
<PackageReference Include="Bitzsoft.Integrations.CloudDrive.Microsoft365" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Bitzsoft.Integrations.CloudDrive.Microsoft365 --version 1.0.0-alpha.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Bitzsoft.Integrations.CloudDrive.Microsoft365, 1.0.0-alpha.8"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Bitzsoft.Integrations.CloudDrive.Microsoft365@1.0.0-alpha.8
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Bitzsoft.Integrations.CloudDrive.Microsoft365&version=1.0.0-alpha.8&prerelease
#tool nuget:?package=Bitzsoft.Integrations.CloudDrive.Microsoft365&version=1.0.0-alpha.8&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Bitzsoft.Integrations.CloudDrive.Microsoft365
Microsoft 365 企业网盘服务实现,基于 Microsoft Graph API v1.0 覆盖 OneDrive / SharePoint 文件操作。
功能
- 支持 OneDrive 个人版及 SharePoint 文档库
- OAuth 2.0 客户端凭据流认证,令牌自动缓存与刷新
- 小文件直接上传(< 4MB),大文件分块上传会话(最大 250GB)
- 文件/文件夹的增删改查、搜索、共享链接、权限管理、版本管理
安装
dotnet add package Bitzsoft.Integrations.CloudDrive.Microsoft365
<PackageReference Include="Bitzsoft.Integrations.CloudDrive.Microsoft365" Version="*" />
配置
appsettings.json
{
"CloudDrive": {
"Microsoft365": {
"TenantId": "your-tenant-id",
"ClientId": "your-client-id",
"ClientSecret": "your-client-secret",
"BaseUrl": "https://graph.microsoft.com/v1.0",
"AuthorityUrl": "",
"HttpClientName": "Microsoft365CloudDrive",
"LargeFileThreshold": 4194304
}
}
}
配置参数
| 参数 | 必填 | 默认值 | 说明 |
|---|---|---|---|
TenantId |
是 | — | Azure AD 租户 ID |
ClientId |
是 | — | 应用注册的客户端 ID |
ClientSecret |
是 | — | 应用注册的客户端密钥 |
BaseUrl |
否 | https://graph.microsoft.com/v1.0 |
Graph API 基地址 |
AuthorityUrl |
否 | 自动拼接 | OAuth 2.0 令牌端点,为空时按 TenantId 自动拼接 |
HttpClientName |
否 | Microsoft365CloudDrive |
命名 HttpClient 名称 |
LargeFileThreshold |
否 | 4194304 (4MB) |
超过此大小使用上传会话模式 |
Azure AD 应用注册
- 登录 Azure Portal → Azure Active Directory → App registrations
- 新建应用注册,记录 Application (client) ID 和 Directory (tenant) ID
- 在 Certificates & secrets 中创建客户端密钥,记录密钥值
- 在 API permissions 中添加 Microsoft Graph Application permissions:
Files.ReadWrite.All— 文件读写Sites.ReadWrite.All— SharePoint 站点读写(可选)
注册
// 方式一:Action 配置
services.AddBitzsoftMicrosoft365CloudDrive(options =>
{
options.TenantId = "your-tenant-id";
options.ClientId = "your-client-id";
options.ClientSecret = "your-client-secret";
});
// 方式二:IConfiguration 绑定
services.AddBitzsoftMicrosoft365CloudDrive(configuration, "CloudDrive:Microsoft365");
第三方请求日志
内置 Bitzsoft.Integrations.RequestLogging 出站请求记录管道,默认 NullRequestLogStore 不持久化。
// ① 默认:启用记录管道但不持久化(日志丢弃)
services.AddBitzsoftMicrosoft365CloudDrive(options => { /* ... */ });
// ② 持久化:宿主注册 IRequestLogStore 实现后,所有出站请求自动落库
services.AddRequestLogging<MyRequestLogStore>(opts =>
{
opts.MaxBodyLength = 8192; // 单条正文截断上限
opts.SensitiveFields.Add("mySecret"); // 额外脱敏字段
});
services.AddBitzsoftMicrosoft365CloudDrive(options => { /* ... */ });
使用示例
public class MyService
{
private readonly ICloudDriveProvider _drive;
public MyService(ICloudDriveProvider drive) => _drive = drive;
public async Task UploadAsync(Stream fileStream, string fileName)
{
var result = await _drive.UploadAsync(new UploadFileRequest
{
FolderId = "root",
FileName = fileName,
Content = fileStream,
ContentLength = fileStream.Length
});
Console.WriteLine($"上传成功: {result.FileInfo.Id}");
}
}
Graph API 功能矩阵
| 方法 | Graph API 端点 | 说明 |
|---|---|---|
UploadAsync |
PUT content / createUploadSession | 小文件直接上传,大文件分块上传 |
DownloadAsync |
GET items/{id}/content | 下载文件内容流 |
DeleteFileAsync |
DELETE items/{id} | 删除文件 |
MoveFileAsync |
PATCH items/{id} | 更新 parentReference 实现移动 |
CopyFileAsync |
POST items/{id}/copy | 异步复制,返回 202 |
GetFileInfoAsync |
GET items/{id} | 获取文件元数据 |
ListFilesAsync |
GET items/{id}/children | 列出文件夹子项 |
CreateFolderAsync |
POST items/{id}/children | 请求体含 folder facet |
DeleteFolderAsync |
DELETE items/{id} | 删除文件夹 |
SearchAsync |
GET root/search(q='{keyword}') | 全文搜索 |
CreateShareLinkAsync |
POST items/{id}/createLink | 创建匿名/内部共享链接 |
DeleteShareLinkAsync |
DELETE items/{id}/permissions/{pid} | 删除共享链接 |
GetPermissionsAsync |
GET items/{id}/permissions | 获取权限列表 |
SetPermissionAsync |
POST items/{id}/invite | 邀请用户并授权 |
DeletePermissionAsync |
DELETE items/{id}/permissions/{pid} | 删除指定权限 |
ListVersionsAsync |
GET items/{id}/versions | 获取版本列表 |
DownloadVersionAsync |
GET items/{id}/versions/{vid}/content | 下载指定版本 |
RestoreVersionAsync |
POST items/{id}/versions/{vid}/restoreVersion | 恢复到指定版本 |
OAuth 2.0 注意事项
- 使用 客户端凭据流(client_credentials),适用于服务端无用户交互场景
- 令牌默认缓存,过期前 5 分钟自动刷新
- 收到 401 响应时自动重试一次令牌刷新
- 如需访问特定用户 OneDrive,需使用 委托权限流 并传入用户 access token
注意事项
- Graph API 单次请求大小上限 4MB,超过需使用上传会话
- 上传会话最大支持 250GB,分块推荐 4MB
CopyFileAsync是异步操作,返回时不保证复制已完成- SharePoint 文档库操作使用相同的 Graph API,通过站点/列表 ID 区分
依赖
Bitzsoft.Integrations.CloudDrive,企业网盘抽象层Bitzsoft.Integrations.Compatibility,基础工具库
相关包
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Bitzsoft.Integrations.CloudDrive (>= 1.0.0-alpha.8)
- Bitzsoft.Integrations.Compatibility (>= 1.0.0-alpha.8)
- Bitzsoft.Integrations.RequestLogging (>= 1.0.0-alpha.8)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.9)
- Microsoft.Extensions.Http (>= 10.0.9)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.9)
-
net5.0
- Bitzsoft.Integrations.CloudDrive (>= 1.0.0-alpha.8)
- Bitzsoft.Integrations.Compatibility (>= 1.0.0-alpha.8)
- Bitzsoft.Integrations.RequestLogging (>= 1.0.0-alpha.8)
- Microsoft.Extensions.Configuration.Abstractions (>= 5.0.0)
- Microsoft.Extensions.Http (>= 5.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 5.0.0)
-
net8.0
- Bitzsoft.Integrations.CloudDrive (>= 1.0.0-alpha.8)
- Bitzsoft.Integrations.Compatibility (>= 1.0.0-alpha.8)
- Bitzsoft.Integrations.RequestLogging (>= 1.0.0-alpha.8)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.9)
- Microsoft.Extensions.Http (>= 10.0.9)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.9)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Bitzsoft.Integrations.CloudDrive.Microsoft365:
| Package | Downloads |
|---|---|
|
Bitzsoft.Integrations.CloudDrive.All
企业网盘服务聚合包 — 包含所有供应商实现 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-alpha.8 | 44 | 7/1/2026 |
| 1.0.0-alpha.7 | 57 | 6/16/2026 |
| 1.0.0-alpha.6 | 61 | 6/16/2026 |
| 1.0.0-alpha.5 | 56 | 6/14/2026 |
| 1.0.0-alpha.4 | 41 | 7/1/2026 |
| 1.0.0-alpha.3 | 54 | 6/7/2026 |