2

I'm building a Dotnet Core web app that needs to allow the Windows-Authenticated user to browse through the connected virtual directories and view and select files hosted there.

Is there a way for a Dotnet Core application to access a virtual directory? And barring that, is there a way for a regular Dotnet application to do it?

2

1 Answer 1

6

It is possible to do so. I've been working on this thing for two weeks now, looked everywhere to get an answer. Here is how I did it.

You will need to add in the configure app.UseFileServer() in the Configure method of the Startup.cs

app.UseFileServer(new FileServerOptions
{
    PhysicalFileProvider("\\\\virtualPath\\photos\\wait\\"),
    RequestPath = new PathString("/AROULETTE"),
    EnableDirectoryBrowsing = true
});

How does this work? The way it is set up, you would enter http://localhost:5000/AROULETTE and it would open the virtual path provided in the PhysicalFileProvider in the browser. Of course this is not what I actually wanted.

I needed to create a directory and copy files into the virtual directory with C#. Once I had the FileServer setup, I tried something like this which does not work.

if(!Directory.Exists("/AROULETTE/20170814"))
{
    Directory.Create("/AROULETTE/20170814")
}

of course, neither does this

var path = Path.Combine("http://localhost:5000/", "AROULETTE/20170814")
if(!Directory.Exists(path)
{
    Directory.Create(path)
}

Instead, you just use the actual virtual path of the folder.

if(!Directory.Exists("\\\\virtualPath\\photos\\wait\\20170814"))
{
    Directory.Create("\\\\virtualPath\\photos\\wait\\20170814")
}

Thus UseFileServer is used to create a "bridge" between the application and the virtual folder the same way that you would create a virtual directory with ASP.Net 4.5

Hope this can help some people because most of the answers about this topic were not clear at all.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.