Click here to Skip to main content
15,885,760 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm making a program that launches links in an exe file in WinForms .NET desktop application, I want the user to change text in the richtextbox and press "Launch all" and they all open in a new window Edge, I did it, but the Properities.Settings.Default.fullText when made
= RichTextBoxURLs.Text
and then Properities.Settings.Default.Save(); is called, when I move the exe file to another folder it loses the fullText and it becomes empty in settings, what's the easiest way to make the exe file retain a string in it even when it moves to a different path or a different folder?

The user would be able to send the exe to a friend and the friend would see the same text in the richtextbox.

What I have tried:

I also tried creating and dynamically editing a string in Properties.Resources and it tells me it's read only.
Posted
Updated 10-May-23 21:57pm
v4
Comments
Richard MacCutchan 11-May-23 4:13am    
You need to move the settings file with the executable each time they change.

1 solution

You don't change the content of EXE files: partly because they normally reside in a write-protected folder under "Program Files", partly because that kind of activity triggers anti-virus software like crazy, partly because the file is in use while the app is running and can't be changed, but mostly because it's a very bad idea with modern apps.

The way I handle this is to use the built in data folders windows includes: Where Should I Store My Data?[^] covers this.
You might want to look at this as well: Instance Storage - A Simple Way to Share Configuration Data among Applications[^] - it's not exactly what you need (it's a bit more involved than that) but it adds a degree of flexibility you may not have considered.
 
Share this answer
 
Comments
RobertoSky 11-May-23 11:10am    
I want to make sure that you understand although I think you understand, I want to copy the exe file from Debug folder, and put text in it and send the exe alone to a friend and make him see the text I have put in it, is that possible? I can for example send him a folder of the exe and a txt file in a rar/zip file and let the exe read the contents of the text file that is in the same folder as it... is this the only and best way?
Edit: I made it with the txt file way, is this the best plz?
OriginalGriff 11-May-23 12:10pm    
A ZIP is maybe a bad idea - just sending the EXE file doesn't mean the app will be able to run on his computer!
The simplest solution is to make a deployment project for the app solution and include the text file in that.
RobertoSky 11-May-23 12:15pm    
What do you mean by deployment project plz?
OriginalGriff 11-May-23 12:58pm    
https://learn.microsoft.com/en-us/visualstudio/deployment/deploying-applications-services-and-components
RobertoSky 11-May-23 13:07pm    
You mean publishing the program to be installed in Windows rather than copying the EXE with a text file in a folder for both files only in a RAR? How do I transfer the text from one computer to another by moving a file to it? when I install the program on my computer, how do I move it to another computer? it's only the install folder that I can move. I need to be able to change the text file when the text in the richtextbox changes, and then when I open the application (EXE or installed), I need to write to the text file and read it later on another computer. How does having an install folder (made in Publish) in Windows desktopn .NET C# make the installation remember the texr when moved to another computer plz?

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