943,712 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 1159
  • VB.NET RSS
Aug 12th, 2009
0

Saving a file: Default Extension, Name & Folder

Expand Post »
Hello, i am currently developing a new OpenSource project.
I will release it to the public this week. :-)

Let's get to my question(s) then:
  • I have a Rich Text Box, and i want to save that text into a default extension.
  • I want the default name to be found in the textbox, E.g: Hello my name is Zack (The file would appear as default name Zack on the Save File Dialog, but if the name was Richards, it would appear Richards instead).
  • Also, the Save File Dialog should open a default folder. (.../Saved)


I lack knowledge in saving files on VB.NET, any help would be greatly appreciated and a great boost on my project.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Zack Richards is offline Offline
5 posts
since Aug 2009
Aug 12th, 2009
0

Re: Saving a file: Default Extension, Name & Folder

Add a savefiledialog (here sfd) to your form
the following code you add into your save click event
vb Syntax (Toggle Plain Text)
  1. With sfd
  2. .FileName = stri.Replace("Hello my name is ", "") & ".rtf"
  3. .InitialDirectory = My.Application.Info.DirectoryPath & "/Saved/"
  4. .ShowDialog()
  5. End With

and the next code you just add to your code
vb Syntax (Toggle Plain Text)
  1. Private Sub sfd_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles sfd.FileOk
  2. RichTextBox1.SaveFile(sfd.FileName, RichTextBoxStreamType.RichText)
  3. End Sub
Last edited by GeekByChoiCe; Aug 12th, 2009 at 2:26 am. Reason: bb codes :@
Featured Poster
Reputation Points: 208
Solved Threads: 168
Practically a Master Poster
GeekByChoiCe is offline Offline
692 posts
since Jun 2009
Aug 12th, 2009
0

Re: Saving a file: Default Extension, Name & Folder

very good
Reputation Points: 10
Solved Threads: 1
Newbie Poster
freepost is offline Offline
20 posts
since Aug 2009
Aug 12th, 2009
0

Re: Saving a file: Default Extension, Name & Folder

Thank you, you really helped me.
Will be sure to stay here at DaniWeb.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Zack Richards is offline Offline
5 posts
since Aug 2009
Aug 12th, 2009
0

Re: Saving a file: Default Extension, Name & Folder

What do you mean with "stri", it says that it is not declared.
I am using Visual Basic 2008
Last edited by Zack Richards; Aug 12th, 2009 at 9:00 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Zack Richards is offline Offline
5 posts
since Aug 2009
Aug 12th, 2009
0

Re: Saving a file: Default Extension, Name & Folder

stri can be replaced by Textbox1.Text
Featured Poster
Reputation Points: 208
Solved Threads: 168
Practically a Master Poster
GeekByChoiCe is offline Offline
692 posts
since Jun 2009
Aug 12th, 2009
0

Re: Saving a file: Default Extension, Name & Folder

Thanks, this is almost solved.
The problem is:
  • if there is a large text in the textbox, i would like to delete it from the filename, only getting the "my name is Zack" part, therefore making it possible to write a whole text and it finds "my name is Zack" somewhere, and gets Zack as filename (Zack has example, could be Richards or anything else.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Zack Richards is offline Offline
5 posts
since Aug 2009
Aug 13th, 2009
0

Re: Saving a file: Default Extension, Name & Folder

Thats pretty hard if the text is always different. A simple solution would be that you force the user to write their name into a sepearate textbox so you can use that as the file name.
If you want to stick to the solution you already have then it will be pretty hard because you never know where the name is and users normally never stick to the syntax, so you cant trust them that they will always write "hello my name is blabla"
Featured Poster
Reputation Points: 208
Solved Threads: 168
Practically a Master Poster
GeekByChoiCe is offline Offline
692 posts
since Jun 2009
Aug 13th, 2009
0

Re: Saving a file: Default Extension, Name & Folder

This would be used for a Java Compiler.
Which always has the "public class Scriptname" part, which "Scriptname" has to be the name of the file.
Thank you for your help, but is it anyway to do this?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Zack Richards is offline Offline
5 posts
since Aug 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: How to find extact word from a column in SQL Table.
Next Thread in VB.NET Forum Timeline: Using wrapper functions for a C++ class (exported in a DLL) in VB.NET app





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC