save file dialog?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

how can i create a code to make my program create an rtf file? heres what i
have so far, any help would be appreciated:
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuSave.Click
Me.SaveFileDialog1.ShowDialog()
Me.SaveFileDialog1.CheckFileExists = True
Me.SaveFileDialog1.CheckPathExists = True
Me.SaveFileDialog1.AddExtension = True
Me.SaveFileDialog1.DereferenceLinks = True
Me.SaveFileDialog1.DefaultExt = ".rtf"
End Sub
 
That still didnt work, should it look like:
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuSave.Click
Me.SaveFileDialog1.ShowDialog()
Me.SaveFileDialog1.CheckFileExists = True
Me.SaveFileDialog1.CheckPathExists = True
Me.SaveFileDialog1.AddExtension = True
Me.SaveFileDialog1.DereferenceLinks = True
Me.SaveFileDialog1.Filter = "RTF Files (*.rtf)|*.rtf"

End Sub
 
Dim strFilename As String
With SaveFileDialog1
.DefaultExt = "rtf"
.Filter = "RTF (*.rtf)|*.rtf|All Files (*.*)|*.*"
.FilterIndex = 0
.InitialDirectory =
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
If .ShowDialog = DialogResult.OK Then
strFilename = .FileName
Else
Exit Sub
End If
End With
MessageBox.Show(strFilename)
 
You originally asked about the file save dialog, which you got.

Here;s the full code to create the file too:

Dim strFilename As String
With SaveFileDialog1
.DefaultExt = "rtf"
.Filter = "RTF (*.rtf)|*.rtf|All Files (*.*)|*.*"
.FilterIndex = 0
.InitialDirectory =
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
If .ShowDialog = DialogResult.OK Then
strFilename = .FileName
Else
Exit Sub
End If
End With
Dim sw As New IO.StreamWriter(strFilename)
sw.Close()

That will do the trick. Just copy/paste it in your menu click event.

By the way: It creates an EMPTY file & closes it.
 
if i go to the open dialog will the file open and have everything that was
shwon on the screen?
 
RTF files are usually handled by MS Word or Wordpad if MS Office isn't
installed. You will notice the file icon is either Wordpad or MS Word

So, use the same idea as the save file dialog & it shall open
 
whats the open file code if i wanted to open this file? and will it show it
exactly how i left it if there are pictures, labels, and text boxes or should
i use a different file format?
 
The code that goes between the StreamWriter & the close should be from a RTF
textbox & not a normal textbox.

Then use this code (incomplete) to open a Stream Reader object to put the
file into your RTF textbox:

Dim strFilename As String
With OpenFileDialog1
.DefaultExt = "rtf"
.Filter = "RTF (*.rtf)|*.rtf|All Files (*.*)|*.*"
.FilterIndex = 0
.InitialDirectory =
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
If .ShowDialog = DialogResult.OK Then
strFilename = .FileName
Else
Exit Sub
End If
End With

As you see, its the same code, but using an OpenFileDialog instead.
 
i copied and pasted a code form the site but it gave me errors all over the
place, and the open thing didnt work, when i opend the file nuthing happened
 
it also doesnt save anytghing besides an empty file, am i asking too much out
of VB or can i save a my project as a file type with pictures, labels,
buttons etc and oepn it up and edit it later?
 
iwdu15 said:
how can i create a code to make my program create an rtf file? heres what
i
have so far, any help would be appreciated:
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuSave.Click
Me.SaveFileDialog1.ShowDialog()

'SaveFileDialog' only shows the file selection dialog, but it doesn't
actually create files or save data to files. You will have to do that
yourself:

\\\
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Me.RichTextBox1.SaveFile(OpenFileDialog1.FileName)
End If
///
 
well then how do u save data to a file so i can open it exactly ghow it was
and start editing it again? im using visual studio.net 2003 btw
 
I said above that it saves an EMPTY file

I have done a 20-hour day & I am not being funny, but I am not just here to
help you out.

I thought you only wanted the filter line of code. I do not have the time to
write you a full application & add comments to it. I am dead on my feet.
Please don't take it the wrong way if I sound a little off.

Please type:

http://www.google.com & in the search box type:

"RTF", "VB.NET" (including quotes) & press Enter
 
iwdu15 said:
well then how do u save data to a file so i can open it exactly ghow it
was
and start editing it again? im using visual studio.net 2003 btw

Place a richtextbox control on your form and use this code to load a file:

\\\
Me.RichTextBox1.LoadFile("C:\foo.rtf")
///
 
ok forgive me for being stupid but this is just my first year programming
anything this complicated so whjat type of rich text control, and how do i
save a file with the data from my applicaton and what format should i have it
save as?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top