1

I have a SaveFileDialog to download file.

It works fine until I host the website on IIS. Then it starts to open a debugger.

My code:

string downloadUrl = string.Empty;
var newThread = new Thread((ThreadStart)(() =>
{

    FolderBrowserDialog fbd = new FolderBrowserDialog();
    fbd.ShowNewFolderButton = true;
    if (fbd.ShowDialog() == DialogResult.Cancel)
        return;

    downloadUrl = fbd.SelectedPath;

}));
newThread.SetApartmentState(ApartmentState.STA);
newThread.Start();
newThread.Join();
Balagurunathan Marimuthu
  • 2,927
  • 4
  • 31
  • 44
Yashasvi
  • 197
  • 1
  • 3
  • 6
  • 3
    Am I missing something, why are you using Windows controls on a website? And in another thread (which you then join rendering it moot anyhow)... – Lloyd Oct 13 '16 at 08:24
  • When you say 'it works fine', where did it works? In IIS Express, while debugging on VS? Or before you move the snippets from a Winform project into an ASP.NET one? – Martheen Oct 13 '16 at 08:29
  • Hi, I want to download file at user's selected location. So, I am using FolderBrowserDialog. I have also used SaveFileDialog but same behavior. I was getting STA error without including another thread. – Yashasvi Oct 13 '16 at 08:31
  • _I want to download file at user's selected location. So, I am using FolderBrowserDialog_ You can't do this. It only worked locally because Visual Studio showed the dialog, not the website. – stuartd Oct 13 '16 at 08:32
  • @stuartd Is there any alternative to achieve this? – Yashasvi Oct 13 '16 at 08:39
  • 1
    Just send the download to the browser, and let it ask the user what to do. – stuartd Oct 13 '16 at 08:52
  • @stuartd That I can not do, because file will be in .zip format and I need to extract it within the function. So, my whole functionality will be, click on download button, select a location to download, get that path and extract it at same location. – Yashasvi Oct 13 '16 at 09:57
  • @Yashasvi That's not how websites work, you have no control outside of the browser sandbox. The user has to do all that or you'll need some kind of application for the user side. – Lloyd Oct 13 '16 at 10:04

0 Answers0