473,396 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

save file dialog

GJP
Hello.

Ive been asked to make my own notepade for college assignment.

All ig going well, but i cant get the save to work.

I can get Save a (shows dialog box), i can get it to just save too, but when
i try to put an IF in it to check if the file has already been saved before,
it will not save.

Private Sub mnuSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuSave.Click
'fname is a var, set it to file name
fname = SFD.FileName()
If fname > "0" Then
'save the file will current name
rtb1.SaveFile(SFD.FileName, RichTextBoxStreamType.RichText)
Else
'need to do a save as if got this far
'title box
SFD.Title = "Please chose a folder and a name for your file"
'rich text format
SFD.Filter = "Rich Text Files (*.rtf)|*.rtf"
SFD.FilterIndex = 1
result = SFD.ShowDialog
If result = DialogResult.OK Then
rtb1.SaveFile(SFD.FileName, RichTextBoxStreamType.RichText)
fname = SFD.FileName
End If
End If

End Sub

Any ideas? Thanks!
--

Do something amazing give Blood

http://www.blood.co.uk
Nov 20 '05 #1
10 4313
Cor
Hi GJP,

Normaly should this be enough using the save Dialog box
(but you can do more with it)
\\\
Dim sfd As New SaveFileDialog
sfd.Title = "Please chose a folder and a name for your file"
sfd.Filter = "Rich Text Files (*.rtf)|*.rtf"
sfd.FilterIndex = 1
If sfd.ShowDialog = DialogResult.OK Then
rtb1.SaveFile(sfd.FileName, RichTextBoxStreamType.RichText)
End If
///

If someone chooses a file that already exist the savefiledialog ask if it
has to be overwritten. And if he sais "save" (depends on your
langagesettings), that is with this routine done (and when it not exist it
is just written).

Cor
Nov 20 '05 #2
GJP

"Cor" <no*@non.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
If someone chooses a file that already exist the savefiledialog ask if it
has to be overwritten. And if he sais "save" (depends on your
langagesettings), that is with this routine done (and when it not exist it
is just written).

Cor


Not sure if i explained my self properly before, I have a menu item ('Save')
that when you press it it will save the file. The code i posted (for
'Save') is suposed to check if you have saved the file before(by doing a
'Save As'), if you have, then it will save the file under that name('Save'),
but if you have not, it will ask you to name the file -ie, dialog box opens
(Imagine going to 'File' then 'Save' in note pad - it will ask you to give
it a name if it has not been saved before, but if you have already done a
'Save As', it will just save it).

If i do a 'save as' first, edit the text in rtb1, then click 'save' it will
work, but if i close the program, reopen it, edit the text in rtb1 and then
'save' it does not save it, i have messed around, its either the sub
'mnuSave_click' or the sub 'mnuOpen_click' that is giving me the problem,
but i cant work it out

Here the code:

''''I have the variable 'fname' that is used to check if the file already
has been saved (it will have a file name if it has)

''''Code for 'Save As':

Private Sub mnuSaveAs_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuSaveAs.Click
SFD.Title = "Please chose a folder and a name for your file"
SFD.Filter = "Rich Text Files (*.rtf)|*.rtf"
SFD.FilterIndex = 1
result = SFD.ShowDialog
If result = DialogResult.OK Then
rtb1.SaveFile(SFD.FileName, RichTextBoxStreamType.RichText)
fname = SFD.FileName
End If
End Sub

''''Code for 'Save'

Private Sub mnuSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuSave.Click
'fname is a var, set it to file name
fname = SFD.FileName()
If fname > "0" Then
'save the file will current name
rtb1.SaveFile(SFD.FileName, RichTextBoxStreamType.RichText)
Else
'need to do a save as
SFD.Title = "Please chose a folder and a name for your file"
SFD.Filter = "Rich Text Files (*.rtf)|*.rtf"
SFD.FilterIndex = 1
result = SFD.ShowDialog
If result = DialogResult.OK Then
rtb1.SaveFile(SFD.FileName, RichTextBoxStreamType.RichText)
fname = SFD.FileName
End If
End If
End sub

''''Code for open

Private Sub mnuOpen_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuOpen.Click

OFD.Title = "Please chose a folder and the name of your file"
OFD.Filter = "Rich Text Files (*.rtf)|*.rtf"
OFD.FilterIndex = 1
result = OFD.ShowDialog
If result = DialogResult.OK Then
rtb1.LoadFile(OFD.FileName)
fname = OFD.FileName
End If
Me.Text = OFD.FileName
End Sub
Nov 20 '05 #3
Cor
Hi GJP,

You mean something as this?
\\\
Private Sub mnuSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuSave.Click
If fname = sfd.FileName Then
'save the file will current name
rtb1.SaveFile(sfd.FileName, RichTextBoxStreamType.RichText)
Else
mnuSaveas_Click(Nothing, Nothing)
End If
End Sub
///

I optimezed it a little bit but the only thing that gives you the trouble is
I think this,
If fname > "0" Then
Why would the fname be something as "0"


Not sure if i explained my self properly before, I have a menu item

('Save') that when you press it it will save the file. The code i posted (for
'Save') is suposed to check if you have saved the file before(by doing a
'Save As'), if you have, then it will save the file under that name('Save'), but if you have not, it will ask you to name the file -ie, dialog box opens (Imagine going to 'File' then 'Save' in note pad - it will ask you to give
it a name if it has not been saved before, but if you have already done a
'Save As', it will just save it).

If i do a 'save as' first, edit the text in rtb1, then click 'save' it will work, but if i close the program, reopen it, edit the text in rtb1 and then 'save' it does not save it, i have messed around, its either the sub
'mnuSave_click' or the sub 'mnuOpen_click' that is giving me the problem,
but i cant work it out

Here the code:

''''I have the variable 'fname' that is used to check if the file already
has been saved (it will have a file name if it has)

''''Code for 'Save As':

Private Sub mnuSaveAs_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuSaveAs.Click
SFD.Title = "Please chose a folder and a name for your file"
SFD.Filter = "Rich Text Files (*.rtf)|*.rtf"
SFD.FilterIndex = 1
result = SFD.ShowDialog
If result = DialogResult.OK Then
rtb1.SaveFile(SFD.FileName, RichTextBoxStreamType.RichText)
fname = SFD.FileName
End If
End Sub

''''Code for 'Save'

Private Sub mnuSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuSave.Click
'fname is a var, set it to file name
fname = SFD.FileName()
If fname > "0" Then
'save the file will current name
rtb1.SaveFile(SFD.FileName, RichTextBoxStreamType.RichText)
Else
'need to do a save as
SFD.Title = "Please chose a folder and a name for your file"
SFD.Filter = "Rich Text Files (*.rtf)|*.rtf"
SFD.FilterIndex = 1
result = SFD.ShowDialog
If result = DialogResult.OK Then
rtb1.SaveFile(SFD.FileName, RichTextBoxStreamType.RichText) fname = SFD.FileName
End If
End If
End sub

''''Code for open

Private Sub mnuOpen_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuOpen.Click

OFD.Title = "Please chose a folder and the name of your file"
OFD.Filter = "Rich Text Files (*.rtf)|*.rtf"
OFD.FilterIndex = 1
result = OFD.ShowDialog
If result = DialogResult.OK Then
rtb1.LoadFile(OFD.FileName)
fname = OFD.FileName
End If
Me.Text = OFD.FileName
End Sub

Nov 20 '05 #4
Cor
Hi GJP,

You mean something as this?
\\\
Private Sub mnuSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuSave.Click
If fname = sfd.FileName Then
'save the file will current name
rtb1.SaveFile(sfd.FileName, RichTextBoxStreamType.RichText)
Else
mnuSaveas_Click(Nothing, Nothing)
End If
End Sub
///

I optimezed it a little bit but the only thing that gives you the trouble is
I think this,
If fname > "0" Then
Why would the fname be something as "0"


Not sure if i explained my self properly before, I have a menu item

('Save') that when you press it it will save the file. The code i posted (for
'Save') is suposed to check if you have saved the file before(by doing a
'Save As'), if you have, then it will save the file under that name('Save'), but if you have not, it will ask you to name the file -ie, dialog box opens (Imagine going to 'File' then 'Save' in note pad - it will ask you to give
it a name if it has not been saved before, but if you have already done a
'Save As', it will just save it).

If i do a 'save as' first, edit the text in rtb1, then click 'save' it will work, but if i close the program, reopen it, edit the text in rtb1 and then 'save' it does not save it, i have messed around, its either the sub
'mnuSave_click' or the sub 'mnuOpen_click' that is giving me the problem,
but i cant work it out

Here the code:

''''I have the variable 'fname' that is used to check if the file already
has been saved (it will have a file name if it has)

''''Code for 'Save As':

Private Sub mnuSaveAs_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuSaveAs.Click
SFD.Title = "Please chose a folder and a name for your file"
SFD.Filter = "Rich Text Files (*.rtf)|*.rtf"
SFD.FilterIndex = 1
result = SFD.ShowDialog
If result = DialogResult.OK Then
rtb1.SaveFile(SFD.FileName, RichTextBoxStreamType.RichText)
fname = SFD.FileName
End If
End Sub

''''Code for 'Save'

Private Sub mnuSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuSave.Click
'fname is a var, set it to file name
fname = SFD.FileName()
If fname > "0" Then
'save the file will current name
rtb1.SaveFile(SFD.FileName, RichTextBoxStreamType.RichText)
Else
'need to do a save as
SFD.Title = "Please chose a folder and a name for your file"
SFD.Filter = "Rich Text Files (*.rtf)|*.rtf"
SFD.FilterIndex = 1
result = SFD.ShowDialog
If result = DialogResult.OK Then
rtb1.SaveFile(SFD.FileName, RichTextBoxStreamType.RichText) fname = SFD.FileName
End If
End If
End sub

''''Code for open

Private Sub mnuOpen_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuOpen.Click

OFD.Title = "Please chose a folder and the name of your file"
OFD.Filter = "Rich Text Files (*.rtf)|*.rtf"
OFD.FilterIndex = 1
result = OFD.ShowDialog
If result = DialogResult.OK Then
rtb1.LoadFile(OFD.FileName)
fname = OFD.FileName
End If
Me.Text = OFD.FileName
End Sub

Nov 20 '05 #5
GJP

"Cor" <no*@non.com> wrote in message
news:ug**************@TK2MSFTNGP09.phx.gbl...
Hi GJP,

You mean something as this?


Yeah, but if you click on 'Save' it opens the OFD, for some reason, fname is
not being set as the file name. Where should i put fname = file name bit of
code. I have it as:

Private Sub mnuOpen_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuOpen.Click
OFD.Title = "Please chose a folder and the name of your file"
OFD.Filter = "Rich Text Files (*.rtf)|*.rtf"
OFD.FilterIndex = 1
result = OFD.ShowDialog
If result = DialogResult.OK Then
rtb1.LoadFile(OFD.FileName)
fname = OFD.FileName
End If
Me.Text = OFD.FileName
End Sub

I put a break point on the line 'fname = ofd.filename' and fname showed up
as empty
Thanks
Gav.
Nov 20 '05 #6
GJP

"Cor" <no*@non.com> wrote in message
news:ug**************@TK2MSFTNGP09.phx.gbl...
Hi GJP,

You mean something as this?


Yeah, but if you click on 'Save' it opens the OFD, for some reason, fname is
not being set as the file name. Where should i put fname = file name bit of
code. I have it as:

Private Sub mnuOpen_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuOpen.Click
OFD.Title = "Please chose a folder and the name of your file"
OFD.Filter = "Rich Text Files (*.rtf)|*.rtf"
OFD.FilterIndex = 1
result = OFD.ShowDialog
If result = DialogResult.OK Then
rtb1.LoadFile(OFD.FileName)
fname = OFD.FileName
End If
Me.Text = OFD.FileName
End Sub

I put a break point on the line 'fname = ofd.filename' and fname showed up
as empty
Thanks
Gav.
Nov 20 '05 #7
GJP
Just seen that it does set fname as file name in the open sub, but in the
Save sub, file name has been changed to doc1, but i dont know how....

"GJP" <ga***@gMYSECONDNAME4397.fsnet.co.uk> wrote in message
news:bp**********@newsg2.svr.pol.co.uk...
Yeah, but if you click on 'Save' it opens the OFD, for some reason, fname is not being set as the file name. Where should i put fname = file name bit of code. I have it as:

Private Sub mnuOpen_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuOpen.Click
OFD.Title = "Please chose a folder and the name of your file"
OFD.Filter = "Rich Text Files (*.rtf)|*.rtf"
OFD.FilterIndex = 1
result = OFD.ShowDialog
If result = DialogResult.OK Then
rtb1.LoadFile(OFD.FileName)
fname = OFD.FileName
End If
Me.Text = OFD.FileName
End Sub

I put a break point on the line 'fname = ofd.filename' and fname showed up as empty
Thanks
Gav.

Nov 20 '05 #8
GJP
Just seen that it does set fname as file name in the open sub, but in the
Save sub, file name has been changed to doc1, but i dont know how....

"GJP" <ga***@gMYSECONDNAME4397.fsnet.co.uk> wrote in message
news:bp**********@newsg2.svr.pol.co.uk...
Yeah, but if you click on 'Save' it opens the OFD, for some reason, fname is not being set as the file name. Where should i put fname = file name bit of code. I have it as:

Private Sub mnuOpen_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuOpen.Click
OFD.Title = "Please chose a folder and the name of your file"
OFD.Filter = "Rich Text Files (*.rtf)|*.rtf"
OFD.FilterIndex = 1
result = OFD.ShowDialog
If result = DialogResult.OK Then
rtb1.LoadFile(OFD.FileName)
fname = OFD.FileName
End If
Me.Text = OFD.FileName
End Sub

I put a break point on the line 'fname = ofd.filename' and fname showed up as empty
Thanks
Gav.

Nov 20 '05 #9
Cor
Hi GJP,

I hope it works now totaly, we changed the saveas, save and now the open, It
will be look nicer also.

Private Sub mnuOpen_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuOpen.Click
OFD.Title = "Please chose a folder and the name of your file"
OFD.Filter = "Rich Text Files (*.rtf)|*.rtf"
OFD.FilterIndex = 1
result = OFD.ShowDialog
If result = DialogResult.OK Then
rtb1.LoadFile(OFD.FileName)
fname = OFD.FileName sfd.FileName = ofd.FileName End If
Me.Text = OFD.FileName
End Sub


Cor
Nov 20 '05 #10
GJP
Cor, you are a star!

Its working :)

Now that ive got that bit working i can get the 'New' and 'Exit' working to.
I tried doing it yestarday, but because the save sub was not working, it was
affecting the 'New' and 'Exit' subs.

Anyhow, thanks for your help, im new to VB, so would have taken me much
longer to work out the problems if you didnt help.

Ta

Gav.
"Cor" <no*@non.com> wrote in message
news:Om**************@TK2MSFTNGP11.phx.gbl...
Hi GJP,

I hope it works now totaly, we changed the saveas, save and now the open, It will be look nicer also.

Private Sub mnuOpen_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuOpen.Click
OFD.Title = "Please chose a folder and the name of your file"
OFD.Filter = "Rich Text Files (*.rtf)|*.rtf"
OFD.FilterIndex = 1
result = OFD.ShowDialog
If result = DialogResult.OK Then
rtb1.LoadFile(OFD.FileName)
fname = OFD.FileName sfd.FileName = ofd.FileName End If
Me.Text = OFD.FileName
End Sub


Cor

Nov 20 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: cathywigzell | last post by:
I have a web page which allows a user to download a file directly to their computer, using IE. I present a file name in a table and the user can then right click on the file name to get a popup...
2
by: Alvo von Cossel I | last post by:
hi, i have a textbox in a form. when you press a Save button, a savefiledialog appears. creating ther file works but everytime you click save, the dialog appears. how do i make the dialog appear...
4
by: John | last post by:
Hi, I generate a report in a comma delimited file and give it a name like MyReport.csv . I then set a Hyperlink control to point tp the file HyperLink1.text = "Download"...
4
by: Richard | last post by:
Hi I'm new to ASP/Web programming so any help would be appreciated... Situation: On my web page I would like to present a link {or button} that would allow the user to download a large file. ...
0
by: Dune | last post by:
Hi there, I have an aspx page that allows users to enter several parameters using drop downs and text boxes. The users then press a button that produces an extract based on the parameters they...
4
by: Dorte | last post by:
Hi, I am using the code below to stream a CSV file with the response object. Dim FileName As String = "Test.csv" With Web.HttpContext.Current.Response ...
1
by: M Pearson | last post by:
Hello there all, am very new to asp.net programming and am struggling with this problem. What I trying to achieve. On a button click I want the standard web save as dialog to display. The user...
4
by: Jonny | last post by:
Hello Group How do I open a Save File Dialog from an ASPX page behind a browse button? Any help would be fantastic!! I am using ASP.NET 1.1 using VB.NET as the coding language TIA
3
by: =?Utf-8?B?YXNkZg==?= | last post by:
Hello. I am making a web application with c# and am using this code: Response.ContentType = "application/x-excel"; Response.AddHeader("Content-Disposition", "attachment;filename=" +...
2
by: vbaDev | last post by:
Hi. I am using Access 2000 and in my code I'm exporting a table into an Excel file (creating it), then the code needs to export another query into the same file (a new worksheet). So I needed both a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.