سؤال

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?

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

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!"));
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top