Save Dailog

G

Guest

Why do I get some odd error about STA thread when I run this code? It seems
to idicate a problem with this line:
if (saveFileDialog1.ShowDialog() == DialogResult.OK)

Code:

private void buttonSaveAs_Click(object sender, EventArgs e)
{
Stream myStream;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();

saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files
(*.*)|*.*";
saveFileDialog1.FilterIndex = 2;
saveFileDialog1.RestoreDirectory = true;

if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((myStream = saveFileDialog1.OpenFile()) != null)
{
// Code to write the stream goes here.
myStream.Close();
}
}

}
 
B

Bob Powell [MVP]

Have you hand-written your main method and forgotten to use the
StaThread attribute?

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
G

Guest

WOw, what the heck is that? I looked in up in the KB and I am still lost. As
you can tell I am new to C#. VB 6.0 was my thing. Can youpoint me to where
I can learn more about this? thanks!


TheMadHatter said:
eg:

[STAThreadAttribute()]
public static main(string[] args)
{
...blabla
}

Bob Powell said:
Have you hand-written your main method and forgotten to use the
StaThread attribute?

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
G

Guest

Na... If you are just upgrading from vb6, dont fret the flags too much.
the only other flag that you will see often is the [serializable()], but
that one
is very well documented when you get into object serialization.

Besides, it was only a week ago I fell into that snag too. :p

Happy hacking

Chris said:
WOw, what the heck is that? I looked in up in the KB and I am still lost. As
you can tell I am new to C#. VB 6.0 was my thing. Can youpoint me to where
I can learn more about this? thanks!


TheMadHatter said:
eg:

[STAThreadAttribute()]
public static main(string[] args)
{
...blabla
}

Bob Powell said:
Have you hand-written your main method and forgotten to use the
StaThread attribute?

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





Chris wrote:
Why do I get some odd error about STA thread when I run this code? It seems
to idicate a problem with this line:
if (saveFileDialog1.ShowDialog() == DialogResult.OK)

Code:

private void buttonSaveAs_Click(object sender, EventArgs e)
{
Stream myStream;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();

saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files
(*.*)|*.*";
saveFileDialog1.FilterIndex = 2;
saveFileDialog1.RestoreDirectory = true;

if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((myStream = saveFileDialog1.OpenFile()) != null)
{
// Code to write the stream goes here.
myStream.Close();
}
}

}
 
G

Guest

Thank you guys. That has solved all of my problems... so far ;o)

TheMadHatter said:
Na... If you are just upgrading from vb6, dont fret the flags too much.
the only other flag that you will see often is the [serializable()], but
that one
is very well documented when you get into object serialization.

Besides, it was only a week ago I fell into that snag too. :p

Happy hacking

Chris said:
WOw, what the heck is that? I looked in up in the KB and I am still lost. As
you can tell I am new to C#. VB 6.0 was my thing. Can youpoint me to where
I can learn more about this? thanks!


TheMadHatter said:
eg:

[STAThreadAttribute()]
public static main(string[] args)
{
...blabla
}

:

Have you hand-written your main method and forgotten to use the
StaThread attribute?

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





Chris wrote:
Why do I get some odd error about STA thread when I run this code? It seems
to idicate a problem with this line:
if (saveFileDialog1.ShowDialog() == DialogResult.OK)

Code:

private void buttonSaveAs_Click(object sender, EventArgs e)
{
Stream myStream;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();

saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files
(*.*)|*.*";
saveFileDialog1.FilterIndex = 2;
saveFileDialog1.RestoreDirectory = true;

if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((myStream = saveFileDialog1.OpenFile()) != null)
{
// Code to write the stream goes here.
myStream.Close();
}
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top