Display folderBrowser dialog from webapp MVC

Pretty new to C # and MVC. I have an MVC application setup in which the webapp is running Chrome as a browser. I have a button inside webapp (html) from which the user can select the folders that he wants, and then I want them to be in fact.

To do this, I make an ajax request to my MVC controller, which will open folderBrowserDialog (System.Windows.Forms) and then return the path back as an ajax response. Everything works fine when I run the application with visual studio. But after creating the application package and installing exe, the BrowserDialog folder does not appear at all. There are no errors causing the ajax response correctly with null

here is the code (part of it)

selectFolderGlobal - global variable

public JObject OpenFolderExplorer() { try { Thread fb= new Thread(new ThreadStart(openFileBrowser), 1); fb.SetApartmentState(ApartmentState.STA); fb.Start(); fb.Join(); JObject selectedFolder = new JObject(); selectedFolder.Add("selectedFolder", selectedFolderGlobal); return selectedFolder; } catch (Exception ex) { Logger.Log(" Exception: " + ex.Message); JObject errorcode = JObject.Parse(mConstants.EXCEPTION); return errorcode; } } private void openFileBrowser() { try { var fbd= new FolderBrowserDialog(); fbd.ShowNewFolderButton = false; DialogResult result = fbd.ShowDialog(new Form() { TopMost = true, WindowState = FormWindowState.Minimized }); if (result == DialogResult.OK) { selectedFolderGlobal= fbd.SelectedPath; } } catch (Exception ex) { Logger.Entry(" Exception: " + ex.Message); } } 

Ajax response is returned this way

 { "selectedFolder":null } 

Does anyone know why this can happen only after creating the package (after extracting .exe from it)? System.Windows.Forms.dll is added to the dependencies (if this should not have been done, or even building the packages would have failed)

0
c # ajax
source share
1 answer

You are trying to open the view folder dialog on a web server, the user's browser runs on his local machine, even if it works, the user cannot see the dialog that you raised on the server, these are separate machines. And the web application has rights to use files only in the root directory of the web application, you cannot use other folders, and you really do not need it.

You need to understand how web applications work, all C # code is executed on the server, and C # code creates html, css, javascript and other files, then the browser downloads this content and uses it on the local machine. The browser displays html, performs javascript ...

When you debug a local host, your computer is both a server and a client, this is the reason this work works in VS, and you probably run it as an administrator on the local machine.

0
source share

All Articles