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?

2 Answers 2

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

5
  • Do you have a sample file using IFileSystem. There is not one in the repository.
    – jlo-gmail
    Jul 27, 2019 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, 2019 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, 2019 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? Apr 29, 2020 at 10:50
  • The "issues" tab in GitHub contain some examples IIRC
    – Tal Aloni
    Apr 30, 2020 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!"));
2
  • Is that a server too, or just a client? (The question asks for a server) Jul 13, 2017 at 13:35
  • The question asks for a server. SharpCifs is a client. Jul 30, 2017 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.