Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having trouble in publishing my winform application. I store and retrieve images from the resource folder in the base directory of my project using directory string. For example is when the user changes his/her profile image, it store in the resource folder where the program also retrieve for viewing in picturebox (which throws a FileNotFoundException from the given directory path within the code below).

C#
public static readonly string profile_path = Path.GetFullPath(System.Reflection.Assembly.GetExecutingAssembly().Location + @"\..\..\..\Resources\temp\Profiles\");


so i just use it like...

C#
pbxProfile.Image = Image.FromFile(profile_path + "user1.jpg");


Can someone help me or give any idea with this? i am practicing to publish desktop application and i am not sure if im doing it properly regarding with the file store and retrieve. any help is much appreciated.

What I have tried:

I am continuously searching about this and the answers i can find does not fit to what im looking for. specifically, i am looking for proper ways or practice about file store and retrieve with no problems about publishing the application (most likely from the people that have experience with it so i know where i start all over again.).
Posted
Updated 28-Nov-21 0:54am

1 solution

The simple, answer is that you are storing them in the wrong place.
When you publish an app, it gets installed in a folder below either "Program files" or "Program files (x86)" both of which are write protected by default to reduce virus activity.

It works in dev because your app folder hangs off your code folder, and that isn't write protected.

So when you save your profile pics, the system throws an exception - which you are ignoring - because the folder is write protected and you can't put the images there.

The solution? Change where you store your images. This should help: Where should I store my data?[^]
 
Share this answer
 
Comments
Ice Bear 28-Nov-21 7:15am    
yes sir, thats what i've thinkin of in the first place. I just need someone to confirm and explain things much clearer to me. thank you sir.
OriginalGriff 28-Nov-21 7:46am    
You're welcome.

You also need to look at how you are writing the files, and stop ignoring exceptions - the user needs to be told there is a problem if he tries to save his avatar...
Ice Bear 28-Nov-21 8:11am    
Noted on this sir, i indeed handle every exception as possible as i can interpret to warn my user about the problems.

Im recently working with the directory within the local folder in the program files according to the article you have provided sir, it works just fine but another problem has occured. i dont know if it is a problem or by default it creates too many folder with weird names such as C:\Users\icebear\AppData\Local\Apps\2.0\9OTDLA9J.HWQ\HKW9JQYP.XX7 whenever i install my published app.
OriginalGriff 28-Nov-21 8:22am    
You'll have to look to your installer to work that out!
Ice Bear 28-Nov-21 8:26am    
noted on this matter sir, thanks a lot!.

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