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();
}
}
} 5 1490
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();
}
}
}
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();
}
}
}
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();
}
}
>
}
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();
}
}
}
>
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();
}
}
>
}
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: F. Hall |
last post by:
If I read a bitmap image from one file and save it to another the save
operation is slow unless I draw on the image. In other words,
Image inputImage = Image.FromFile( @"c:\temp\source.bmp" );...
|
by: David Deacon |
last post by:
I use the Save Dailog box and it works fine in returning a string
I know want to return a picture into a OLE or ???
the Function in the BrowseDialog is
Function GetOpenFile(Optional varDirectory...
|
by: GJP |
last post by:
Hello.
Ive been asked to make my own notepade for college assignment.
All ig going well, but i cant get the save to work.
I can get Save a (shows dialog box), i can get it to just save too,...
|
by: Viks |
last post by:
Hi everyone,
I am beginner at javascript.One of the web
applications that i am currently developing,requires to upload file
from the client side to the server.The condition being that the file...
|
by: jharikrishna |
last post by:
Hi Frnds
I am working on c#.
I want the information about to click the button in textbox How to
Open the file browser dailog.
|
by: batchu rajesh |
last post by:
in a vb.net programming i need to keep a color dailog box in a pannel
can any one help me how to do
|
by: =?Utf-8?B?RnJlZU5FYXN5?= |
last post by:
Hello,
the scenario:
There's an ASPX page which shows some text and has three buttons at the
bottom: Save, Print and Close. Print and close is done by javascript. But how
can I save the page...
|
by: ChillUmesh |
last post by:
hi,
i've to filter out files without any extension using common dailog control can any one help me out.
thnx
|
by: ppardi |
last post by:
I'm developing an addin for Word 2007 and I need to determine whether a user
saves a Word 2007 document in an older format (97-2003) after a save as is
done. The scenario is that the user starts...
|
by: premMS143 |
last post by:
Hi,
I' developing a VB application. When user clicks on 'Tools' option from the Main Form, a dailog box will appear, which is developed using another VB form itself. But while the dailog box is...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |