https://github.com/raidenyn/yandexdisk.client
Yandex Disk API Client for .NET
https://github.com/raidenyn/yandexdisk.client
Last synced: 12 months ago
JSON representation
Yandex Disk API Client for .NET
- Host: GitHub
- URL: https://github.com/raidenyn/yandexdisk.client
- Owner: raidenyn
- License: mit
- Created: 2015-11-20T23:32:50.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2022-09-19T17:39:06.000Z (almost 4 years ago)
- Last Synced: 2025-05-17T07:19:26.097Z (about 1 year ago)
- Language: C#
- Size: 128 KB
- Stars: 41
- Watchers: 8
- Forks: 14
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Yandex Disk API Client for .NET
[Yandex Disk Rest API](https://tech.yandex.ru/disk/rest/) client library for .NET Standard
[](https://ci.appveyor.com/project/raidenyn/yandexdisk-client/branch/master)
## How to install
From [NuGet](https://www.nuget.org/packages/YandexDisk.Client/) or
[MyGet](https://www.myget.org/feed/yandexdisk-client)
```cmd
PM> Install-Package YandexDisk.Client
```
## Changes in version 1.3
- Now the library is supporting .NET Standard 2.0 and available for .NET Core.
- Removed supporting of .NET 4.0 and 4.5
## How to use
Example of uploading file to Yandex Disk
```C#
async Task UploadSample()
{
//You should have oauth token from Yandex Passport.
//See https://tech.yandex.ru/oauth/
string oauthToken = ""
// Create a client instance
IDiskApi diskApi = new DiskHttpApi(oauthToken);
//Upload file from local
await diskApi.Files.UploadFileAsync(path: "/foo/myfile.txt",
overwrite: false,
localFile: @"C:\myfile.txt",
cancellationToken: CancellationToken.None);
}
```
Example of downloading files from Yandex Disk
```C#
async Task DownloadAllFilesInFolder(IDiskApi diskApi)
{
//Getting information about folder /foo and all files in it
Resource fooResourceDescription = await diskApi.MetaInfo.GetInfoAsync(new ResourceRequest
{
Path = "/foo", //Folder on Yandex Disk
}, CancellationToken.None);
//Getting all files from response
IEnumerable allFilesInFolder =
fooResourceDescription.Embedded.Items.Where(item => item.Type == ResourceType.File);
//Path to local folder for downloading files
string localFolder = @"C:\foo";
//Run all downloadings in parallel. DiskApi is thread safe.
IEnumerable downloadingTasks =
allFilesInFolder.Select(file =>
diskApi.Files.DownloadFileAsync(path: file.Path,
localPath: System.IO.Path.Combine(localFolder, file.Name)));
//Wait all done
await Task.WhenAll(downloadingTasks);
}
```
## How to build
Open solution src/YandexDisk.Client.sln in Visual Studio 2017 (support C# 7.3 is required). Run build solution.