I'm trying to create my first File Dialog box using C# and MS Web Developer 2010. I got the System.Windows.Forms reference set up (from the .NET tab, the one on the COM tab gave me an error), and imported the namespace OK. I found a few very helpful newbie sites for this and I've got the code below.
My problem is that when I invoke it with a button, my browser gives me the 'Waiting for Localhost' message forever and nothing happens. (I did minimize all windows to make sure my dialog box isn't hiding behind something else.) There are a number of posts on forums, including here on StackOverflow (WinFors GUI Hangs When Calling OpenFileDialog.ShowDialog), that discuss this issue, but I can't find a solution.
A lot of forums discuss a resolution that involve making my .NET processes run on different threads. Could it be that Microsoft actually expects me to understand that kind of thing to use this simple control?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void OpenDialog(object sender, EventArgs e)
{
String MyFile = string.Empty;
String input = string.Empty;
OpenFileDialog dialog = new OpenFileDialog();
dialog.ShowHelp = true;
dialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
dialog.InitialDirectory = "D:";
dialog.Title = "This is a test dialog";
dialog.ShowDialog();
}
}
EDIT (from comment)
What I'm trying to do is to allow my user to save a file created on the site to a folder of his choosing.