Click here to Skip to main content
15,922,894 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to get file path which is (C:\Program Files\Company name\InventorySetup\configSetting.ini).
But i am not allowed to write file path hardcoded in program. how do i get this path programatically by providing filename(co.ini) and drive name (C:\). Actually i my application is installed on server PC and its shortcuts created on client PC desktop and when client PC uses application by shortcuts it gets file path from server PC but i want to do client pc should use its own file path as application also installed in client PC.

How can i achieve this? if anyone not understand my scenario please let me know.

Presently i uses path which gives path where application file (exe) installed, in program like below.

What I have tried:

C#
protected string file = Path.GetDirectoryName(Application.ExecutablePath).Replace("bin\\Debug", "") + "\\configSetting.ini";
Posted
Updated 2-Dec-16 19:29pm

1 solution

First) If your config file is beside your exe file and it is read only and won't change then you can use:
C#
protected string file = Path.GetDirectoryName(Application.ExecutablePath) + "\\configSetting.ini";

Second) If your config file changes then you should save in the users data folder instead (since "Program Files" is protected by Windows and requires admin permissions for writing to): Where should I store my data?[^]
 
Share this answer
 
Comments
Member 11543226 3-Dec-16 1:57am    
I have full access to write anything into "Company name" folder of this path ("C:\Program Files\Company name\InventorySetup").
Mehdi Gholam 3-Dec-16 2:10am    
Only on setup, when using it normally UAC is checked and enforced.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900