0

I am creating a .Net Core web application to view log files and other result files that reside on the web server as well as start and stop some applications that produce those files. I see references to OpenFileDialog, but for the life of me can't find how to resolve that reference. I get type or namespace OpenFileDialog cannot be found, are you missing a reference... Of course I'm missing a reference! The problem is that even when one finds an example of the use, no one seems to mention what their "using" statement was to get that. System.Windows.Forms isn't the answer as it says Forms isn't in System.Windows. Is there any guidance on how to find the correct NuGet package to include? How to find the using statement? Even the Microsoft Documentation doesn't tell you what package it is in.

I want to have a web page open and set the directory to the folder on the server where the results are placed, and then select a result file or a log file and open it. If I hard code the path, the code works fine,

    public void OnGet()
    {
        string directory = @"a directory";
        using (OpenFileDialog openFileDialog = new OpenFileDialog() )
        {
// the OpenFileDialog is underlined and says, no namespace, etc.
        }
        string logFile = String.Concat(directory, @"a file in the directory");
        logContent.Append(String.Format(@"<h2>{0}</h2>", logFile));

...

7
  • 2
    OpenFileDialog is a WinForms (native Windows) class, this is not available on a web page. Commented Nov 9, 2018 at 16:05
  • What do I use instead. The documentation doesn't make this clear at all. Commented Nov 9, 2018 at 16:05
  • Here is an example: learn.microsoft.com/en-us/aspnet/core/mvc/models/… Commented Nov 9, 2018 at 16:07
  • Thanks, but this uploads a file from my desktop to the server. I need to browse for a file on the server in a given directory to open it and view the file. Commented Nov 9, 2018 at 16:13
  • 1
    If you want to select a local file (i.e. on the users PC) then Neils link is the way to do it, if you want to select a file on the server you are going to need to create that UI/logic yourself, for example by enumerating the directory and returning a list. Commented Nov 9, 2018 at 16:14

1 Answer 1

2

There isn't an easy way to do this, because the files are on the server yet you want a UI on the client. You'll need a round-trip every time the user changes directories.

You could just enable directory browsing for those folders in IIS (assuming those directories are in wwwroot) but be careful as the user will be able to see everything in there. This allows the user to download and view files on the server, but doesn't tell you what they selected, so you couldn't use that file for input to your code.

https://www.ntweekly.com/2017/07/21/enable-directory-browsing-in-iis-10-and-windows-server-2016/

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.