Search code examples
c#setup-project

Saving file to a directory when porgram installed on another computer.


I created a setup project with installshield to install my program on other computers. I have to save an image to use later. But the image is not being saved on the directory that i created. Here is the line:

image.Save(Application.StartupPath + "\\data\\config\\Choosen.bmp");

(Application.StartupPath = C:\Program Files (x86)\PT\My Product Name). After this line an image has to be in the directory but there is nothing.

and the directory C:\Program Files (x86)\PT\My Product Name\data\config exists. The code work when i execute it from the solution project, but when i install it to another computer it doesn't work. I am sure somebody knows the answer :)

Thanks


Solution

  • It's quite likely that you don't have permission to edit files at that path.

    You're better off saving any data in the user's application data folder

    var path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
    

    or using a resource file: MSDN - Adding and Editing Resources (Visual C#).