5

I need to represent some specific data as files in file share. Data is stored in a database and it needs some processing during the access. For this purpose, CIFS server is ideal solution. Does anybody know any CIFS/SMB server implementation in C#/.NET?

Sharepoint is doing something similar. Anybody knows how they do it? Is it a CIFS server or some sort of extension to Windows CIFS server?

Marko Vodopija
  • 578
  • 6
  • 12

2 Answers2

5

You can use SMBLibrary, it's an open-source SMB 1.0/CIFS, SMB 2.0 and SMB 2.1 server implementation in C#.

You can implement the IFileSystem interface and expose your database objects as a shared folder.

https://github.com/TalAloni/SMBLibrary

Tal Aloni

Tal Aloni
  • 1,429
  • 14
  • 14
  • Do you have a sample file using IFileSystem. There is not one in the repository. – jlo-gmail Jul 27 '19 at 19:37
  • 1
    Hi Tal Aloni, I checked the code on git which link you provided above. But can you let me know that in that code where you are using your SMB Library and Server? I also have your latest code with SMBLibrary.Win32. Can you please define the steps that how to use your library with above implementation? Thanks – Deepak Oct 11 '19 at 10:45
  • @Deepak, you can find the client code under SMBLibrary\Client and the server code under SMBLibrary\Server. I have included a server usage example as part of that code, and there are client examples under issues in GitHub. – Tal Aloni Oct 11 '19 at 19:46
  • Hi @TalAloni, Is there any documentation or example of writing a file from the local system to a networked SMB share using this NuGet package? – Ankush Jain Apr 29 '20 at 10:50
  • The "issues" tab in GitHub contain some examples IIRC – Tal Aloni Apr 30 '20 at 11:30
-3

SharpCifs.Std is .Net Standard1.3 implements.
You can use on .Net Framework4.6 or higher, .Net Core1.0, and Xamarin.iOS/Android
Here is NuGet package.

Use it like this:

//reading file
var file = new SmbFile("smb://UserName:Password@ServerName/ShareName/Folder/FileName.txt"));
var readStream = file.GetInputStream();
var buffer = new byte[1024*8];
var memStream = new MemoryStream();
int size;
while ((size = readStream.Read(buffer, 0, buffer.Length)) > 0)
    memStream.Write(buffer, 0, size);

Console.WriteLine(Encoding.UTF8.GetString(memStream.ToArray()));

//writing file
var file = new SmbFile("smb://UserName:Password@ServerName/ShareName/Folder/NewFileName.txt"));
file.CreateNewFile();
var writeStream = file.GetOutputStream();
writeStream.Write(Encoding.UTF8.GetBytes("Hello!"));
ume05rw
  • 11
  • 2