C# Move files from one directory to another on Azure File share

Viewed 1085

I'm working on a requirement where I need to read and process CSV files on Azure File share via a C# console app. Once the file is processed, I need to move it to Archived folder, and in case of errors move it to Error folder, The fileshare structure is as below:

csvfileshare --> Name of the fileshare on Azure under the storage account. This contains the .CSV files(csvfileshare/demo.csv) csvfileshare/Archived --> Name of dir/folder under csvfileshare where the files should be moved if successful csvfileshare/Error --> Name of dir/folder under csvfileshare where the files should be moved if file has errors

Can you please guide me on how this can be achieved in C# console application, I've got to the point where I'm able to read the file from Azure fileshare into the console app and process them, but unable to move it to one of these directories post the processing.

Thanks!

1 Answers

You may have used this module already to read the file (in that case you have everything you need) but answer is using azure.storage.blob.fileshare package. If you use Visual Studio, go to manage NuGet packages and search for Azure storage.

Following Microsoft Document describes the process to manipulate Azure storage files using the module pretty well.

https://docs.microsoft.com/en-us/azure/storage/files/storage-dotnet-how-to-use-files?tabs=dotnet

By the way, in Azure world, downloading/processing/uploading is not a very scalable model (as the client finally becomes a bottleneck), you may want to explore the possibility of using something like Azure logic apps or function apps, especially if you want to process very large number of files.

Related