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

Save to a file

P: n/a
Ok, I need a little help. :) So far, I've written a program that will allow
a user to browse for a file (via a dialog box) and open the selected file. I
need to make some slight modifications to that and have the user's data
(entered into a textbox) saved to a selected file (from the dialog
box)...here's what I have done so far. I was hoping that someone could steer
me in the right direction. Thanks!

Dim myFileDlog As New OpenFileDialog

myFileDlog.InitialDirectory = "C:\"

myFileDlog.Filter = "Text Files |*.txt|All files | *.*"

If myFileDlog.ShowDialog() = DialogResult.OK Then

Dim sFileName As String = myFileDlog.FileName

Dim sFileExtension As String = (sFileName.Substring(sFileName.Length - 4))

Select Case sFileExtension.ToUpper

Case ".TXT"

Shell("notepad.exe " & sFileName, AppWinStyle.MaximizedFocus)

Case ".DOC"

Shell("path to word.exe goes here" & sFileName, AppWinStyle.MaximizedFocus)

Case ".XLS"

Shell("path to excel.exe goes here " & sFileName,
AppWinStyle.MaximizedFocus)

Case Else

MsgBox("not a valid file extension")

End Select

Else

MsgBox("User pressed Cancel.")

End If
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Kelly,

* "Kelly" <ke**********@amerock.com> scripsit:
Ok, I need a little help. :) So far, I've written a program that will allow
a user to browse for a file (via a dialog box) and open the selected file. I
need to make some slight modifications to that and have the user's data
(entered into a textbox) saved to a selected file (from the dialog
box)...here's what I have done so far. I was hoping that someone could steer
me in the right direction. Thanks!
Use the 'SaveFileDialog' instead of the 'OpenFileDialog'.
Dim myFileDlog As New OpenFileDialog

myFileDlog.InitialDirectory = "C:\"

myFileDlog.Filter = "Text Files |*.txt|All files | *.*"
Remove the spaces in front of and behind the pipe characters ("|").
If myFileDlog.ShowDialog() = DialogResult.OK Then

Dim sFileName As String = myFileDlog.FileName

Dim sFileExtension As String = (sFileName.Substring(sFileName.Length - 4))
Use 'System.IO.Path.GetExtension' instead of 'Substring'.
Select Case sFileExtension.ToUpper

Case ".TXT"

Shell("notepad.exe " & sFileName, AppWinStyle.MaximizedFocus)

Case ".DOC"

Shell("path to word.exe goes here" & sFileName, AppWinStyle.MaximizedFocus)

Case ".XLS"

Shell("path to excel.exe goes here " & sFileName,
AppWinStyle.MaximizedFocus)

Case Else

MsgBox("not a valid file extension")

End Select

Else

MsgBox("User pressed Cancel.")

End If


\\\
myFileDlog.Dispose()
///

I am not sure what your question is a about. Do you want to know how to
write data to a file? Take a look at the methods in
'Microsoft.VisualBasic.FileSystem' ('FileOpen', 'WriteLine',
'FileClose', ...) and in the 'System.IO' namespace ('StreamWriter',
....).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #2

P: n/a
Thanks for the tips! Yes, I'm trying to write the data the user enters into
a file.

I looked at the Write and WriteLine methods, but didn't quite understand
where the FileNumber comes in and whether or not I needed to create one. I'm
pretty new at .NET, so this is a big learning experience. Quite different
than VB6!

Thanks again!

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2o************@uni-berlin.de...
Kelly,

* "Kelly" <ke**********@amerock.com> scripsit:
Ok, I need a little help. :) So far, I've written a program that will allow a user to browse for a file (via a dialog box) and open the selected file. I need to make some slight modifications to that and have the user's data
(entered into a textbox) saved to a selected file (from the dialog
box)...here's what I have done so far. I was hoping that someone could steer me in the right direction. Thanks!
Use the 'SaveFileDialog' instead of the 'OpenFileDialog'.
Dim myFileDlog As New OpenFileDialog

myFileDlog.InitialDirectory = "C:\"

myFileDlog.Filter = "Text Files |*.txt|All files | *.*"


Remove the spaces in front of and behind the pipe characters ("|").
If myFileDlog.ShowDialog() = DialogResult.OK Then

Dim sFileName As String = myFileDlog.FileName

Dim sFileExtension As String = (sFileName.Substring(sFileName.Length - 4))
Use 'System.IO.Path.GetExtension' instead of 'Substring'.
Select Case sFileExtension.ToUpper

Case ".TXT"

Shell("notepad.exe " & sFileName, AppWinStyle.MaximizedFocus)

Case ".DOC"

Shell("path to word.exe goes here" & sFileName,

AppWinStyle.MaximizedFocus)
Case ".XLS"

Shell("path to excel.exe goes here " & sFileName,
AppWinStyle.MaximizedFocus)

Case Else

MsgBox("not a valid file extension")

End Select

Else

MsgBox("User pressed Cancel.")

End If


\\\
myFileDlog.Dispose()
///

I am not sure what your question is a about. Do you want to know how to
write data to a file? Take a look at the methods in
'Microsoft.VisualBasic.FileSystem' ('FileOpen', 'WriteLine',
'FileClose', ...) and in the 'System.IO' namespace ('StreamWriter',
...).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #3

P: n/a
Kelly,

* "Kelly" <ke**********@amerock.com> scripsit:
Thanks for the tips! Yes, I'm trying to write the data the user enters into
a file.

I looked at the Write and WriteLine methods, but didn't quite understand
where the FileNumber comes in and whether or not I needed to create one. I'm
pretty new at .NET, so this is a big learning experience. Quite different
than VB6!


\\\
Dim f As Integer = FreeFile()
FileOpen(f, "C:\foo.txt", OpenMode.Append)
PrintLine(f, "Hello Kelly!")
PrintLine(f, "Hello World!")
FileClose(f)
///

If you are unsure about how to use a certain function, and you are using
VB.NET Standard or VS.NET, simply place the caret over the keyword and
press the F1 key to go to the documentation + samples.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #4

P: n/a
Kelly,
Ok, I need a little help. :) So far, I've written a program that will allow a user to browse for a file (via a dialog box) and open the selected file. That is extremely easy and you did that already
I need to make some slight modifications to that and have the user's data
(entered into a textbox) saved to a selected file (from the dialog
box)...here's what I have done so far. I was hoping that someone could steer me in the right direction. Thanks!


That can be probably extremely difficult when you mean that you want to set
the sentence in a textbox and than add that to the file in a I do not know
what place.

For the txt file you do not need the notepad however you should read the
file in an array or whatever.

For the doc and the xls you need in every way you want to do it interop. You
can start for that looking here.

Office
http://support.microsoft.com/default...b;EN-US;311452

http://msdn.microsoft.com/office/

Pia Download
http://www.microsoft.com/downloads/d...displaylang=en

I hope this gives some ideas?

Cor
Nov 21 '05 #5

P: n/a
Thank you. This is extremely helpful!

-Kelly

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2o************@uni-berlin.de...
Kelly,

* "Kelly" <ke**********@amerock.com> scripsit:
Thanks for the tips! Yes, I'm trying to write the data the user enters into a file.

I looked at the Write and WriteLine methods, but didn't quite understand
where the FileNumber comes in and whether or not I needed to create one. I'm pretty new at .NET, so this is a big learning experience. Quite different than VB6!


\\\
Dim f As Integer = FreeFile()
FileOpen(f, "C:\foo.txt", OpenMode.Append)
PrintLine(f, "Hello Kelly!")
PrintLine(f, "Hello World!")
FileClose(f)
///

If you are unsure about how to use a certain function, and you are using
VB.NET Standard or VS.NET, simply place the caret over the keyword and
press the F1 key to go to the documentation + samples.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #6

P: n/a
Thanks!! What I'm trying to set up is a csv file of sorts. There will be
numerous textboxes that the users will need to fill in. Then, they will
choose the file they want to save the data to (different file for each
customer) and the data will be appended to the end of the file. Later, this
will be imported into a database.

This really isn't a project that nees to be done for work. I'm really just
trying to jump into .NET and get a feel for the language and learn a few
things that will come in handy down the road for work. The program I'm
writing now will incorporate several differnet functions that I will be able
to reuse later on.

Thanks for the links!

-Kelly
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:ut*************@TK2MSFTNGP12.phx.gbl...
Kelly,
Ok, I need a little help. :) So far, I've written a program that will allow
a user to browse for a file (via a dialog box) and open the selected

file. That is extremely easy and you did that already
I need to make some slight modifications to that and have the user's data
(entered into a textbox) saved to a selected file (from the dialog
box)...here's what I have done so far. I was hoping that someone could steer
me in the right direction. Thanks!


That can be probably extremely difficult when you mean that you want to

set the sentence in a textbox and than add that to the file in a I do not know
what place.

For the txt file you do not need the notepad however you should read the
file in an array or whatever.

For the doc and the xls you need in every way you want to do it interop. You can start for that looking here.

Office
http://support.microsoft.com/default...b;EN-US;311452

http://msdn.microsoft.com/office/

Pia Download
http://www.microsoft.com/downloads/d...displaylang=en
I hope this gives some ideas?

Cor

Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.