Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,042 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,594 people online right now. Registration is fast and FREE... Join Now!




Open and Save dialogs

 
Reply to this topicStart new topic

Open and Save dialogs

unlimited
29 Feb, 2008 - 03:49 PM
Post #1

New D.I.C Head
*

Joined: 16 Apr, 2007
Posts: 27


My Contributions
hi again. I was wondering how to make a save or open file dialog actually work. for example I want to make the dialog to be able to know what format I want the file to be saved (witch is RTF and TXT formats) and I want the open file dialog to open RTF and TXT files only...

basically i'm using the RTF component to act as a writing area so I want to be able to make the text savable and the possibility to open files...

i'm using the
CODE
me.toolstripbutton7.savefiledialog.show
line of code and
CODE
me.toolstripbutton6.openfiledialog.show
code. this only opens the dialogs....

hope is clear enough what i'm asking smile.gif

any help appreciated biggrin.gif


User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Open And Save Dialogs
29 Feb, 2008 - 04:06 PM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
To set it so the user can only save as certain types you need to set the Filter Property. To determine which button the user selected on your dialog, check the DialogResult value. Here is a small example of working with the 2 items I linked to:


vb

Private Sub button1_Click(sender As Object, e As System.EventArgs) Handles button1.Click()
'Create a stream to hold the file data
Dim myStream As Stream
'Create a FileSaveDialog
Dim sfd As New SaveFileDialog()
'Set the filter of the SaveFileDialog
sfd.Filter = "RichText Files (*.rtf)|*.rtf|Text Files (*.txt)|*.txt"
'Set the selected file type
sfd.FilterIndex = 2
'Setting this property to true will
'cause the dialog to remember the last
'directory the user was in
sfd.RestoreDirectory = True

'Now check the DialogResult to see what the user selected
If sfd.ShowDialog() = DialogResult.OK Then
'Since they selected OK (Save) we need to
open the file and add it to our Stream
myStream = sfd.OpenFile()
'Now make sure the user selected a file
If (myStream IsNot Nothing) Then
' Code to save the file goes here
'Now close your stream
myStream.Close()
End If
End If
End Sub


Hope that helps a little smile.gif
User is offlineProfile CardPM
+Quote Post

unlimited
RE: Open And Save Dialogs
29 Feb, 2008 - 04:13 PM
Post #3

New D.I.C Head
*

Joined: 16 Apr, 2007
Posts: 27


My Contributions
thanks for the quick response smile.gif ...
I will try the code soon but thanks again so much smile.gif

just wondering, will this allow me to open a text file as well? as in use one button for save and one for open file, etc...




This post has been edited by unlimited: 29 Feb, 2008 - 04:16 PM
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Open And Save Dialogs
29 Feb, 2008 - 04:15 PM
Post #4

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
No problem, glad I could help. Now tell all your programming friends about us smile.gif
User is offlineProfile CardPM
+Quote Post

unlimited
RE: Open And Save Dialogs
29 Feb, 2008 - 04:19 PM
Post #5

New D.I.C Head
*

Joined: 16 Apr, 2007
Posts: 27


My Contributions
QUOTE(PsychoCoder @ 29 Feb, 2008 - 05:15 PM) *

No problem, glad I could help. Now tell all your programming friends about us smile.gif


hehe I already did but not many of my friends are into programming sad.gif. oh well smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 09:54PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month