Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Final example
static void Main()
{
var folderName = "pdf-demo";
var localFolder = $@"C:\asposedemo\{folderName}\";
var fileExistResponse = _storageApi.GetIsExist(new GetIsExistRequest(folderName, null, storageName));
if (fileExistResponse.Code == 200)
if (fileExistResponse.FileExist.IsFolder == false)
{
var createFolderResponse = _storageApi.PutCreateFolder(new PutCreateFolderRequest(folderName, null, storageName));
if (createFolderResponse.Code != 200)
{
Console.WriteLine("CreateFolder response is not OK!");
Console.WriteLine(createFolderResponse.ToString());
return;
}
}
else
{
var filesResponse = _storageApi.GetListFiles(new GetListFilesRequest(folderName, storageName));
if (filesResponse.Code == 200)
{
var filesInCloudFolder = filesResponse.Files.Where(f => f.IsFolder == false).Select(item => item.Name).ToList();
var filesInLocalFodler = new DirectoryInfo(localFolder).GetFiles().Select(fi => fi.Name);
foreach (var fileName in filesInLocalFodler.Except(filesInCloudFolder))
{
Console.WriteLine($"Uploading {fileName}");
var fileStream = new FileStream($@"{localFolder}\{fileName}", FileMode.Open);
var uploadResponse = _storageApi.PutCreate(new PutCreateRequest($"/{folderName}/{fileName}", fileStream));
}
}
}
else
{
Console.WriteLine("FileExist response response is not OK!");
Console.WriteLine(fileExistResponse.ToString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment