469,352 Members | 2,140 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

save file dialog?

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
Nov 21 '05 #1
21 6977
SaveFileDialog1.Filter = "RTF Files (*.rtf)|*.rtf"
Nov 21 '05 #2

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
Nov 21 '05 #3
Dim strFilename As String
With SaveFileDialog1
.DefaultExt = "rtf"
.Filter = "RTF (*.rtf)|*.rtf|All Files (*.*)|*.*"
.FilterIndex = 0
.InitialDirectory =
Environment.GetFolderPath(Environment.SpecialFolde r.Desktop)
If .ShowDialog = DialogResult.OK Then
strFilename = .FileName
Else
Exit Sub
End If
End With
MessageBox.Show(strFilename)
Nov 21 '05 #4
i put that in, it says its saved yet the file isnt there
Nov 21 '05 #5
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.SpecialFolde r.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.
Nov 21 '05 #6
if i go to the open dialog will the file open and have everything that was
shwon on the screen?
Nov 21 '05 #7
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
Nov 21 '05 #8
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?
Nov 21 '05 #9
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.SpecialFolde r.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.
Nov 21 '05 #10
Sorry. Forgot the link:

http://www.vb-helper.com/index_graphics.html

Look under graphics for screen printing/capturing

"iwdu15" wrote:
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?

Nov 21 '05 #11
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
Nov 21 '05 #12
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?
Nov 21 '05 #14
i 4got to tell u i dont kno if it matters im using Visual studio.Net 2003
Nov 21 '05 #15
"iwdu15" <iw****@discussions.microsoft.com> schrieb:
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
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #16
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
Nov 21 '05 #17
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

"Crouchie1998" wrote:
Have a look at this article I found for you:

http://www.vbdotnetheaven.com/Code/Sept2003/2163.asp

Code sample:

http://www.vbdotnetheaven.com/Code/S...ViewerCode.zip

Nov 21 '05 #18
"iwdu15" <iw****@discussions.microsoft.com> schrieb:
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")
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #19
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?
Nov 21 '05 #20
can anybody tell me how to save a file and create it with data from inside a
indows form on visual studio 2003? i want it to save whats in labels, text
boxes and images if it makes a difference...thanks
Nov 21 '05 #21
Isdu15

MSDN is (mostly) a great source .

Here is a complete sample about all your questions you had in this message
thread.

http://msdn.microsoft.com/library/de...FileTopic2.asp

I hope this helps?

Cor
Nov 21 '05 #22

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by cathywigzell | last post: by
2 posts views Thread by Alvo von Cossel I | last post: by
4 posts views Thread by John | last post: by
4 posts views Thread by Richard | last post: by
reply views Thread by Dune | last post: by
1 post views Thread by M Pearson | last post: by
4 posts views Thread by Jonny | last post: by
3 posts views Thread by =?Utf-8?B?YXNkZg==?= | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.