4

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.

4 Answers4

7
// 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.

noelicus
  • 14,468
  • 3
  • 92
  • 111
2

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

Datta
  • 819
  • 3
  • 14
  • 27
  • in that case after the installation of my application that folder will be placed where and dose the user can edit that folder? – Ahmed HABBACHI Jan 24 '14 at 10:39
0

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

Community
  • 1
  • 1
astef
  • 8,575
  • 4
  • 56
  • 95
0

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

  • Writing in the current directory will lead to a lot of issues regarding permissions. If you have an executable located under program files, you won't have permissions to write in the directory, unless you run with high privileges. Better places are user's appdata or document directory. – Steve B Jan 24 '14 at 14:44
  • He said that he want to let users to edit content of the folder : *"I want to let the user update the data of that folder"* So how he want to let users to edit content of a folder like AppData (that you said) while it is just in his solution's directory, not in the output executable file (.EXE) ? – Seyed Hamed Shams Jan 25 '14 at 16:31