Re: Saving/opening issues...
Yes it specifically opens Text.txt. Use the OpenFileDialog1.FileName to get the selected file from the users choice.
Re: Saving/opening issues...
Damn, that has got to be the best first post I have ever seen... seriously. He explained what he knew, asked straightforward questions, and posted some of his code. And he got a reply in six minutes. Someone should sticky this to the top of the forum. I think it should be required reading.
Re: Saving/opening issues...
lol, thx experience :) i have read some previous posts and seen how annoyed you guys feel whe people don't post code etc :) didn't want to seem like one of those people :D
with the code, i have replaced the "C:\test.txt" with OpenFileDialog1.FileName like robdogg said earlier but i am now getting an error with these lines:
Code:
Dim objReader As New System.IO.StreamReader(FILE_NAME)
and:
Code:
Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
it says
Quote:
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
does anybody know what is wrong with them?
thanks again :)
Re: Saving/opening issues...
What you need to do is to have a button (or some other control) and when a user click it, you show him/her a open file dialog (or save file dialog) then check the dialog result. If the result is OK then you read the file name and do your stuff. This is sample code to open a text file and read the text into textbox1. Code for using savefiledialog is very much similar.
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ofd As New OpenFileDialog
With ofd
.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
.Filter = "Text Files (*.txt)|*.txt"
.CheckFileExists = True
.Multiselect = False
End With
If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
TextBox1.Text = IO.File.ReadAllText(ofd.FileName)
End If
End Sub
Re: Saving/opening issues...
Cool, this is sort of working, except for a couple of things.
the open dialog opens fine, but when you go to open the file, it opens but then the open dialog opens again. so if you double click a file, it puts the text into textbox1 but then opens the opendialog again.
also, is there a way to change the code so that it opens so that each line of the text file goes in a different textbox, because i have different textboxes that need the information on the different lines to go in them.
But many thanks for this Stanav :D
Re: Saving/opening issues...
Did you use the code exactly as posted? Post your code. It shouldnt be opening twice.
Re: Saving/opening issues...
Ahh sorted to double opening thing. forgot to delete my initial code :blush: :blush:
so is there a way to open the file with different lines going into different boxes?
Re: Saving/opening issues...
You would have to read in the file one line at a time using a streamreader, just one way, and redirecting the contents to whatever textboxes/controls you want.