By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,467 Members | 1,448 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,467 IT Pros & Developers. It's quick & easy.

Save Dailog

P: n/a
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();
}
}

}
Feb 1 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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();
}
}

}
Feb 1 '07 #2

P: n/a

eg:

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

"Bob Powell [MVP]" wrote:
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();
}
}

}
Feb 1 '07 #3

P: n/a
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" wrote:
>
eg:

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

"Bob Powell [MVP]" wrote:
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();
}
}
>
}
Feb 2 '07 #4

P: n/a
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" wrote:
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" wrote:

eg:

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

"Bob Powell [MVP]" wrote:
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();
}
}

}
>
Feb 2 '07 #5

P: n/a
Thank you guys. That has solved all of my problems... so far ;o)

"TheMadHatter" wrote:
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" wrote:
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" wrote:
>
eg:
>
[STAThreadAttribute()]
public static main(string[] args)
{
...blabla
}
>
"Bob Powell [MVP]" wrote:
>
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();
}
}
>
}
Feb 2 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.