Reputation: 25
Been trying to get this to work on my MAC for a while now, but still no luck. In an ASP.NET Core app I am trying to get contents from my network share on a Windows Server. I read you can initiate Static Files through Startup.cs when you include:
app.UseFileServer(new FileServerOptions
{
FileProvider = new PhysicalFileProvider(@"\\192.168.178.101\2020$"),
RequestPath = new PathString("/2020"),
EnableDirectoryBrowsing = false
});
Please note I am running this on a MacOS laptop. I have tried SMB URL also, but no luck. I can connect with the share fine through Finder. I always get the error "The path must be absolute". The share on that server is a folder named 2020. I have tried also without $, but no luck. I also tried to put smb:// in front, but the it saw the UNC as a relative folder path.
I really hope someone can help me with this.
Upvotes: 0
Views: 483
Reputation: 25
In the end I was using a library for this SMBLibrary, but later I even decided to build the solution on a Windows machine, which made it so much easier. Then the SMBLibrary is not even needed.
Upvotes: 0
Reputation: 5041
The address format is not correct. It does not know the protocol. You can install nuget package SharpCifs
and get file as:
var folder = new
SmbFile("smb://UserName:Password@ServerIP/ShareName/FolderName/");
var modeDate = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc);
foreach (SmbFile item in folder.ListFiles())
{
var modeDate = epocDate.AddMilliseconds(item.LastModified()).ToLocalTime();
var name = item.GetName();
var type = item.IsDirectory() ? "dir" : "file";
var date = lastModDate.ToString("yyyy-MM-dd HH:mm:ss");
var msg = $"{name} ({type}) - LastMod: {date}";
}
Upvotes: 0