SharpGrip FileSystem is a versatile .NET file system abstraction that supports multiple storage adapters. It empowers developers to manage various file systems and services through a unified and easily comprehensible API. By coding against the abstractions provided by this library, developers can sidestep vendor-specific APIs, effectively avoiding vendor lock-ins. This flexibility enhances the portability and maintainability of the codebase, allowing for smoother transitions between different file systems.
Reference NuGet package SharpGrip.FileSystem
(https://www.nuget.org/packages/SharpGrip.FileSystem).
For adapters other than the local file system (included in the SharpGrip.FileSystem
package) please see the Supported adapters section.
Adapter | Package | NuGet |
---|---|---|
Local adapter | SharpGrip.FileSystem |
|
AmazonS3 | SharpGrip.FileSystem.Adapters.AmazonS3 |
|
AzureBlobStorage | SharpGrip.FileSystem.Adapters.AzureBlobStorage |
|
AzureFileStorage | SharpGrip.FileSystem.Adapters.AzureFileStorage |
|
Dropbox | SharpGrip.FileSystem.Adapters.Dropbox |
|
FTP | SharpGrip.FileSystem.Adapters.Ftp |
|
GoogleCloudStorage | SharpGrip.FileSystem.Adapters.GoogleCloudStorage |
|
GoogleDrive | SharpGrip.FileSystem.Adapters.GoogleDrive |
|
MicrosoftOneDrive | SharpGrip.FileSystem.Adapters.MicrosoftOneDrive |
|
SFTP | SharpGrip.FileSystem.Adapters.Sftp |
For a full list of the supported operations please see the IFileSystem interface.
var adapters = new List<IAdapter>
{
new LocalAdapter("adapterPrefix", "adapterRootPath")
};
// Instantiation option 1.
var fileSystem = new FileSystem(adapters);
// Instantiation option 2.
var fileSystem = new FileSystem();
fileSystem.Adapters = adapters;
var adapters = new List<IAdapter>
{
new LocalAdapter("local1", "/var/files"),
new LocalAdapter("local2", "D:\\Files")
};
var fileSystem = new FileSystem(adapters);
// Azure connection.
var azureClient = new ShareClient("connectionString", "shareName");
// Dropbox connection.
var dropboxClient = new DropboxClient("oAuth2AccessToken");
var adapters = new List<IAdapter>
{
new LocalAdapter("local", "/var/files"),
new AzureFileStorageAdapter("azure", "/Files", azureClient),
new DropboxAdapter("dropbox", "/Files", dropboxClient)
};
// Copies a file from the `local` adapter to the `azure` adapter.
await fileSystem.CopyFileAsync("local://foo/bar.txt", "azure://bar/foo.txt");
// Moves a file from the `azure` adapter to the `dropbox` adapter.
await fileSystem.MoveFileAsync("azure://Foo/Bar.txt", "dropbox://Bar/Foo.txt");
// Writes string contents to the `azure` adapter.
await fileSystem.WriteFileAsync("azure://Foo.txt", "Bar!");
// Reads a text file from the `dropbox` adapter.
var contents = fileSystem.ReadTextFileAsync("dropbox://Foo.txt");