I want to open a FolderBrowseDialog on button click in MVC razor(VB) syntax.
For that i am calling a jquery function on “onclick” button event and through that function i am making a Post request to function in my controller that contains code to show FolderBrowseDialog.
here is my code.
Html:
<input type="button" class="btn" value="browse" onclick="SelectFolder()"/>
jquery:
<script type="text/javascript">
function SelectFolder()
{
$.post("@Url.Action("FolderPicker", "Home")", function () {
alert('sdd');
},function(ex){
alert("Error occured in AJAX");
});
}
</script>
Controller.. vb code to show FolderBrowserDialog.
<STAThreadAttribute()>
Sub FolderPicker()
Dim browser As FolderBrowserDialog = New FolderBrowserDialog()
browser.Description = "Select Folder"
browser.ShowNewFolderButton = False
browser.RootFolder = Environment.SpecialFolder.Desktop
Dim result As DialogResult = browser.ShowDialog()
If result = DialogResult.OK Then
Dim selectedPath As String = browser.SelectedPath
End If
End Sub
At
Dim result As DialogResult = browser.ShowDialog()
i am getting exception
Current thread must be set to single thread apartment (STA) mode before OLE
calls can be made. Ensure that your Main function has STAThreadAttribute
marked on it. This exception is only raised if a debugger is attached to the
process.
I also included STATreadAttribute() and STATread() but still i get this error.
Am i missing some thing?
Is there any other way to do it?
FolderBrowseDialog is not available in ASP.NET/MVC.
You can read some more stuff here.