Hello All, i was looking for a way to put a string into a program permanently. Im making a portable emailer that you could put on a flash drive. I was wondering how i would go about setting or putting in the persons email and making it stay as a string without using a text file on the flash drive. What i mean is i want the user to set an email and for the email to remain in the program, the only way i know to do this is through the text file. Setting a string within the program doesnt work because the program loses the string when it switches computers.
Cheers!
The only way that I can see it happening is recompiling the application itself by passing the .resources [.resx] file you create at runtime and then pass this file to the EmbeddedResource parameter of your CodeDomProvider instance. To do this, you'll need to:
1: Create a new instance of CodeDomProvider (C# Code Provider).
2: Create a new instance of ResourceWriter which is a part of System.Resources namespace. You will need to give it a filename so it knows where to store the resource.
3: Write your new resource by using the AddResource method of the ResourceWriter instance. E.g: ResourceWriter.AddResource("Password","MyPassword" )
4: Add the newly generated resource file to the Embedded Resources of CodeDomProvider by using: CodeDomProvider.EmbeddedParameters.Add("PathToNewR esourceFile")
5: Compile the code to generate a new assembly. (To get rid of the current assembly, you might want to add some code to CodeDomProvider's entry point to delete the current assembly).
I know this is pretty complex but you can't modify existing embedded resource file when the executable is open. I think that there might be some other way to store the data but I can't think of any of it right now.
The only way that I can see it happening is recompiling the application itself by passing the .resources [.resx] file you create at runtime and then pass this file to the EmbeddedResource parameter of your CodeDomProvider instance. To do this, you'll need to:
1: Create a new instance of CodeDomProvider (C# Code Provider).
2: Create a new instance of ResourceWriter which is a part of System.Resources namespace. You will need to give it a filename so it knows where to store the resource.
3: Write your new resource by using the AddResource method of the ResourceWriter instance. E.g: ResourceWriter.AddResource("Password","MyPassword" )
4: Add the newly generated resource file to the Embedded Resources of CodeDomProvider by using: CodeDomProvider.EmbeddedParameters.Add("PathToNewR esourceFile")
5: Compile the code to generate a new assembly. (To get rid of the current assembly, you might want to add some code to CodeDomProvider's entry point to delete the current assembly).
I know this is pretty complex but you can't modify existing embedded resource file when the executable is open. I think that there might be some other way to store the data but I can't think of any of it right now.
Or, use My.Settings and set it to application scope? Derp.
Originally Posted by Jason
Or, use My.Settings and set it to application scope? Derp.
Aren't application scope settings read only ?
Originally Posted by Hassan
Aren't application scope settings read only ?
Yeah, but so are resources :/. Also, you can user scope them if you need, but seeing as he wanted the string to be "permanent", why would he modify it?
Originally Posted by Jason
Yeah, but so are resources :/. Also, you can user scope them if you need, but seeing as he wanted the string to be "permanent", why would he modify it?
He wants the user to input the email. So that won't work with the application scope. And if he is going to use user scope, the app will lose its settings when the application is moved to another computer. So, once he enters the email, it needs to be entered to the resource file.
Originally Posted by Hassan
He wants the user to input the email. So that won't work with the application scope. And if he is going to use user scope, the app will lose its settings when the application is moved to another computer. So, once he enters the email, it needs to be entered to the resource file.
No, My.Settings stores internally, even via the User scope. If he moves the same .exe to another computer, the settings will be the same. Try it and see
Originally Posted by Jason
No, My.Settings stores internally, even via the User scope. If he moves the same .exe to another computer, the settings will be the same. Try it and see
What ? No, it doesn't. It even loses the settings if I move the app from one location to another with in the same computer. The settings are stored in local filesystem under Application Data folder.
Originally Posted by Hassan
What ? No, it doesn't. It even loses the settings if I move the app from one location to another with in the same computer. The settings are stored in local filesystem under Application Data folder.
What ze fuck? Worked for me fine in the past going from PC to PC. Odd.
Originally Posted by Jason
What ze fuck? Worked for me fine in the past going from PC to PC. Odd.
Hmm, funny how I never experienced that.
Originally Posted by Hassan
The only way that I can see it happening is recompiling the application itself by passing the .resources [.resx] file you create at runtime and then pass this file to the EmbeddedResource parameter of your CodeDomProvider instance. To do this, you'll need to:
1: Create a new instance of CodeDomProvider (C# Code Provider).
2: Create a new instance of ResourceWriter which is a part of System.Resources namespace. You will need to give it a filename so it knows where to store the resource.
3: Write your new resource by using the AddResource method of the ResourceWriter instance. E.g: ResourceWriter.AddResource("Password","MyPassword" )
4: Add the newly generated resource file to the Embedded Resources of CodeDomProvider by using: CodeDomProvider.EmbeddedParameters.Add("PathToNewR esourceFile")
5: Compile the code to generate a new assembly. (To get rid of the current assembly, you might want to add some code to CodeDomProvider's entry point to delete the current assembly).
I know this is pretty complex but you can't modify existing embedded resource file when the executable is open. I think that there might be some other way to store the data but I can't think of any of it right now.
Thank you! Ill be trying that tonight and letting you know how it went, ive always wondered how to do this
Hmm.. I always thought it was saved in the program. Guess that makes sense
Originally Posted by Hassan
What ? No, it doesn't. It even loses the settings if I move the app from one location to another with in the same computer. The settings are stored in local filesystem under Application Data folder.