I don't Really know how
Can someone tell me how
Like you type a string in a textbox and you press a button called "Save" then you want to select the folder you want to save the .txt at.
Thanks
I don't Really know how
Can someone tell me how
Like you type a string in a textbox and you press a button called "Save" then you want to select the folder you want to save the .txt at.
Thanks
How to save Files with a "SaveFileDialog"
Daniel Alvarez
hi,
at the top of your class write "imports system.IO" this is the namespace that contain the streamwriter class
hope this helps
Henry Li
hi, goofu
bad words are not allowed here, plz note all of us here are users like you , just trying to help each others
i see he had answered your question, unless you want someone to write the project for u, do you
here its a part of my project that do the same thing
Private Sub Export()
Dim MySaveDialog As New SaveFileDialog
MySaveDialog.Filter = "Web Page (.Html)|*.HTML|Plain Text (.txt)|*.txt"
MySaveDialog.Title = "Save File"
Dim result As DialogResult = MySaveDialog.ShowDialog()
If Not result = Windows.Forms.DialogResult.Cancel Then
Try
If My.Computer.FileSystem.FileExists(MySaveDialog.FileName) = True Then
'if the file exist remove it
My.Computer.FileSystem.DeleteFile(MySaveDialog.FileName)
End If
'creat new file
Select Case MySaveDialog.FilterIndex
Case 1 'html
WriteHtml(MySaveDialog.Filter)
Case 2 'plaintext
WriteText(MySaveDialog.Filter)
End Select
Catch ex As Exception
MessageBox.Show("problem" & ex.Message)
End Try
End If
End Sub
Public Sub WriteText(ByVal Path As String)
Using MyStreamWriter As StreamWriter = File.CreateText(Path)
'you can use wirteline or write depending or your need
MyStreamWriter.WriteLine("String")
End Using
End Sub
Public Sub WriteHtml(ByVal Where As String)
Using MyStreamWriter As StreamWriter = File.CreateText(Where)
MyStreamWriter.WriteLine("<html><head><style type=""text/css""><!--" & _
"a {font-size: large; font-weight: bold;text-transform: capitalize; color: #CC6600; text-decoration: underline;}" & _
"a:hover{background-color:#FFCC99}" & "div{margin-left:50px}" & _
"--></style></head><body>")
MyStreamWriter.WriteLine("<H2 align=""center""> My Links </h2>")
'... etc
End Using
End Sub
hope this helps
winprock
It's a two step process:
a) Get the file name and file path:
The SaveFileDialog doesn't save anything: it simply allows your user to navigate to an allowed folder and enter a valid filename. The dialog box looks like every other save file dialog box in every other application so your users (usually) know how to use it.
b) Actually save the file:
Once they have used it, you can get the file name, and path, and save your file using file I/O routines.
Which part are you actually having problems with Which piece of code is causing issues Remember, you can use the help that is installed with VB: it'll tell you quite readily how to do both.
FraGar
post Deleted by a moderator
Fedja
Yea it did help.
But I got a strange problem..
This means:
Using
MyStreamWriter As IO.StreamWriter = File.CreateText("C:\")It doesn't know what the bolded text is. It comes with this:
Name "File" is not declared.
What could I do then
Btw.
Im using Visual Studio 2005 Pro