Skip to content

viciousviper/yandexdisk.client

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yandex Disk API Client for .NET

Yandex Disk Rest API client library for .NET 4.6

yandexdisk-client MyGet Build Status

How to use

Example of uploading file to Yandex Disk

async Task UploadSample()
{
  //You should have oauth token from Yandex Passport.
  //See https://tech.yandex.ru/oauth/
  string oauthToken = "<token hear>"

  // 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

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<Resource> 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<Task> downloadingTasks =
        allFilesInFolder.Select(file => diskApi.Files.DownloadFileAsync(file.Path, 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 2015 (support C# 6 is required). Make sure that NuGet restoring option is turn on. Run build solution.

About

Yandex Disk API Client for .NET

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%