C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




.Net


Posted Date: 12 Aug 2008      Total Responses: 3

Posted By: ksdkarthikeyan       Member Level: Silver     Points: 1



Dim fileDialog As New OpenFileDialog
If fileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
TextBox1.Text = fileDialog.FileName
End If

WHILE Execution the FileDialog line. i got the error.. what to do..

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.





Responses

Author: Nagarajan    12 Aug 2008Member Level: GoldRating:     Points: 3

Try this , instead of creating a FileDialog in coding, try dragging a FileDIalog control in the design view iteself,

so that you can use it in your code with out instantiating it.



Author: ksdkarthikeyan    12 Aug 2008Member Level: SilverRating:     Points: 4

dim value as boolean

copy below code and paste in Load events

value = Control.CheckForIllegalCrossThreadCalls
Control.CheckForIllegalCrossThreadCalls = False

i fixed the error..
this is useful for others whose faced this error thank you.



Author: Geetha    12 Aug 2008Member Level: GoldRating:     Points: 6

Private FileName As String
'declaring filename that will be selected
Dim sr As StreamReader
'streamreader is used to read text

Try
With OpenFileDialog1
'With statement is used to execute statements using a particular object, here,_
'OpenFileDialog1
.Filter = "Text files (*.txt)|*.txt|" & "All files|*.*"
'setting filters so that Text files and All Files choice appears in the Files of Type box
'in the dialog
If .ShowDialog() = DialogResult.OK Then
'showDialog method makes the dialog box visible at run time
FileName = .FileName
sr = New StreamReader(.OpenFile)
'using streamreader to read the opened text file
RichTextBox1.Text = sr.ReadToEnd()
'displaying text from streamreader in richtextbox
End If
End With
Catch es As Exception
MessageBox.Show(es.Message)
Finally
If Not (sr Is Nothing) Then
sr.Close()
End If
End Try



Post Reply
You must Sign In to post a response.
Next : Important
Previous : Doubt in Textbox and combobox
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use