views:

203

answers:

0

I have a web application that allows you to download a zip file containing data saved in an oracle blob. For some reason when I make a call to SaveFileDialog.ShowDialog() it shows the dialog behind the browser window, so you have to minimize the browser to use the control.

This is using Visual Studio 2008 with aspx and C#. I am thinking it might be something to do with the fact I am running the application in debug mode, but surely it should work ok.

The following is the code I use:

pk = Convert.ToInt32(e.CommandArgument);
Stream myStream;


SaveFileDialog saveFileDialog = new SaveFileDialog();

saveFileDialog.Filter = "zip files (*.zip)|*.zip|All files (*.*)|*.*";
saveFileDialog.FilterIndex = 2;
saveFileDialog.RestoreDirectory = true;
saveFileDialog.FileName = "C:\\testfile.zip";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
     if ((myStream = saveFileDialog.OpenFile()) != null)
     {
          // Code to write the stream goes here.
          byte[] zipFile = this._presenter.getZipFile(pk);
          string file = saveFileDialog.FileName;
          myStream.Write(zipFile, 0, zipFile.Length);
          myStream.Close();
     }
}

Originally when I tried this code I got the error:

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.

To get around this I used the tag AspCompat="true" in the <%Page %> directive but I'm not too sure what this does or if I should be using it. Any ideas??