Browse through Files

juggernot

Well-known member
Joined
Sep 28, 2006
Messages
173
Programming Experience
Beginner
Hey, I'd like to create a program which can browse through files. First of all I'd like to know if you guys think I can actually do it, second of all I was wondering if you could help point me in the right direction.
 
How do you mean browse through files?

List the files in a directory? Look through a (text?) files contents? Or, display file content regardless of file type? (Text if text, image if image, etc)
 
I found it. The code was
Me.FolderBrowserDialog1.ShowDialog()
That only brings up the dialog tho, I have a lot to learn about how to use it properly in a program.
 
The FolderBrowserDialog is usually used to allow the user to browse the local system for a specific file or folder. When you click ok it will return a path you could then use.

I'm not entirely sure this is what you want...can you give us more detail as to what you are trying to achieve?
 
I guess I really didn't know what I was trying to ask at the beggining. Basically I'm just starting to experiment with the open, save and folderbrowsing dialogs. I was just having trouble getting started, but I believe I'm on the right track now. They basically work as soon as you show the dialog, you just need to edit them a little bit to serve your purposes.

I have saved the path from the folder browser dialog as a variable, which I later use to save a file to.

I'm still working on learning the other dialogs and what they can do, but it doesn't look very complicated.
 
I seem to be having a problem saving files using the savefiledialog. I've saved files before, using a binary formatter. I just thought there was someway to save a file that was built into the savefiledialog, but I can't find it.

If I knew a way to get the path from the savefile dialog I could write my own code to save the file, but the closest thing to that that I could find is 'initial directory.'
 
Soon I'm going to feel kind of silly posting to myself...
Anyhow, I've found out that I am actually supposed to create the code to save the file. I found a website that is really helpful : http://msdn2.microsoft.com/en-US/library/sfezx97z(VS.80).aspx

The only probelem is that the example is for an image, and I'm trying to save text from a messagebox. I was wondering if someone could tell me how to make the nesssecary changes as well as explain the filter and filter index in more detail.
 
use the SaveFileDialog to get a filename and location (use the .FileName() property)

then declare a new StreamWriter with the dialog's filename property as a parameter then write the contents of the text to the file using the StreamWriter's Write & WriteLine methods

also the filter index is which file type the user selected, such as if you list "rtf" and "txt" and they select the rtf one, you use the filter index to know to save the file using an RTF saving method
 
Okay, I've got it so that I can save and load rich text files using the savefile and openfile dialogs. The catch is that the extension has to be .rtf , and I'd like to be able to save it and load it as a different extension. My friend had made a program where he could save richtextfiles under a different extension, and load them in his program. I'm not quite sure how to do this. I'll give you my code:

For SaveFile Dialog:

Me.SaveFileDialog1.CheckPathExists = True
Me.SaveFileDialog1.OverwritePrompt = True

Me.SaveFileDialog1.Filter = "Text Document|*.rtf"

Me.SaveFileDialog1.ShowDialog()
Dim fs As System.IO.FileStream = CType _
(SaveFileDialog1.OpenFile(), System.IO.FileStream)


Select Case SaveFileDialog1.FilterIndex
Case 1

Me.RichTextBox1.SaveFile(fs, _
System.Windows.Forms.RichTextBoxStreamType.RichText)
End Select

For OpenFile Dialog:

Me.OpenFileDialog1.CheckPathExists = True
Me.OpenFileDialog1.CheckFileExists = True
Me.OpenFileDialog1.Filter = "Text Document|*.rtf"



Me.OpenFileDialog1.ShowDialog()
Dim fs As System.IO.FileStream = CType _
(OpenFileDialog1.OpenFile(), System.IO.FileStream)
Select Case SaveFileDialog1.FilterIndex
Case 1

Me.RichTextBox1.LoadFile(fs, _
System.Windows.Forms.RichTextBoxStreamType.RichText)
End Select
 
Also, can I get help with the printdialog? I was looking at it and was a little confused, especially when it comes to the printdialog.document.
 
Back
Top