Question

I am creating an application that uses photos and an XML file all in one folder that I am creating manually, I want to let the user update the data of that folder (Adding Photos, and Editing the Xml file) at run time via the application my question is what is the best approach and where to put that Folder, I know I have to put that relative paths so I am confiused is it in the AppData if so how to do it.

Was it helpful?

Solution

// Use this to get the common directory
string CommonDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);

// And combine it with your own. 
// On Window7 this will return "c:\ProgramData\YourCompany\YourProduct"
string YourDir = Path.Combine(CommonDir, @"YourCompany\YourProduct");

// And create the directory / ensure it exists
System.IO.Directory.CreateDirectory(YourDir);

There are other Special Folders you can get from the system, such as MyDocuments or Desktop as fits your needs best.

OTHER TIPS

first right click on your project explorer and add new folder, it displays empty folder and you put this files into it.

Look at: System.IO.IsolatedStorage

You can manage your files using different scopes of isolation and don't bother about their actual place:

Application - Isolated storage scoped to the application.

Assembly - Isolated storage scoped to the identity of the assembly.

Domain - Isolated storage scoped to the application domain identity.

Machine - Isolated storage scoped to the machine.

None - No isolated storage usage.

Roaming - The isolated store can be placed in a location on the file system that might roam (if roaming user data is enabled on the underlying operating system).

User - Isolated storage scoped by user identity.

(from here: http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragescope(v=vs.110).aspx)

But possibly you don't need such a control over your files isolation. In this case you can simply use local user's aplication folder:

string path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

Look at: Environment.SpecialFolder - a lot of useful places there.

And, of course, you can always use you application's folder:

AppDomain.CurrentDomain.BaseDirectory

Another ways of accessing it: Best way to get application folder path

You shouldn't place the folder in one of your Solution's folder like AppData (AppData is actually a folder, that can contain Database file) because when you finish the development of your application, you just get .EXE output file (That placed in Debug folder) and THAT IS the file that you use it or for example give it to your customer. (But folder like AppData that you said, are placed just in your solution)

So you can create the Folder anywhere you want. But I offer you to create it in the current directory of your application. (.EXE file)

You can refer to the current directory using Environment class => Environment.CurrentDirectory

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top