Saving to the folder with users "My Documents"

When I create the installer for my application, I am going to create a folder in my "My Documents", this folder will be used to save files from my application to.

I want my application to automatically pull up this directory when saving and opening files open. Now my question is: what line do I need to use to get to the folder in "My Documents"?

I know, to get my catalog of my documents, it looks something like this:

Dim dir as String dir = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) 

But what about the folder in my docs? Such as My Documents / Coolest Application of All Files. This project is located on VB.net.

Thanks in advance.

+8
source share
5 answers

Take a look at Path.Combine .

 dir = Path.Combine(dir, "Coolest Application Ever Files") 

Just make sure it exists before you try to write it to a file.

 If Not Directory.Exists(dir) Then Directory.Create(dir) End If 
+9
source share

Well, if you create a folder in the My Documents folder, can you just assume that you already know the name of the specified folder? So will not be:

 dir = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments & "\Your_Folder_Title\") 

Job?

+2
source share
 dim filepath as String filePath= Sys.IO.Path.Combine( My.Computer.FileSystem.SpecialDirectories.MyDocuments, "test.txt") 
+2
source share

Just add the folder you are looking for in the special MyDocuments folder

 dir = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments & "/Coolest Application Ever Files") 
+1
source share

Get the folder in your documents with this line.

 Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "YourAppFolder") 
0
source share

All Articles