hello there guys...
What I was trying to do is, store some values inside of an external file...
For example..
config.ini will contain the Form1 size, ... or maybe a textBox.Text value ...
How would I point the program to read certain file, and load it before it starts?
Thx guys !
Loading

FroglegRank #1,020 · 1.9K reputationPosted Jan 25, 2011, 8:42 PM EST
There is a user setting myString
If that string is null then the application setting constantString will be used by default
Type in the textbox and click button1 and the settings will be saved and label text will change accordingly
FroglegRank #1,020 · 1.9K reputationPosted Jan 23, 2011, 8:39 PM EST
1: In design view open solution explorer (ctrl + alt+L)
2: Right click on your project and select properties , a new window will open
3: On the left open Settings and in the name column a name for your variable eg: myString . Set type to whatever , in this case string
4: To create, put a textbox, label & button on a form. In the button code
yourProjectName.Properties.SettingsDefault.myString = textBox1.Text;
yourProjectName.Properties.SettingsDefault.Save();
5: To use -in form load event = label1.Text = yourProjectName.Properties.SettingsDefault.myString
Save and restart and the label will display saved text
Look through the types and you can save quite a few different values
thiago costaRank #6,113 · 276 reputationPosted Jan 24, 2011, 2:14 PM EST
I got this error :
Error 1 The type or namespace name 'SettingsDefault' does not exist in the namespace 'WindowsFormsApplication2.Properties' (are you missing an assembly reference?) C:\Users\X4-ULTRA\Desktop\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 21 49 WindowsFormsApplication2
:'( ... seems like myString got registered, but for some reasin SettingsDefault does not exist in the namespace...
did i do something wrong?
----EDIT ----
I was reading somethign today, and it seems like .net does no longer support ini files, and it seems like XML is the best way right? ...
so, how would I keep my settings inside of a XML file? ...
For example, a string value, or the size of a form (in pixels) ...
:'( I am so confused..
Let me explain better...
This is my software:
string file; file = TBuemail.Text + ".txt"; string ftp; ftp = "ftp://174.120.150.123/public_html/facebook/" + TBuemail.Text + ".txt"; UploadFile(file, ftp, "username", "password");So, what I am trying to do is:
As you can see the "string" ftp in the program above, is
ftp://174.120.150.123/public_html/f" + TBuemail.Text + ".txt
.... I want to keep the "ftp://174.120.150.123/public_html/f"
inside of a xml, ini, or text file ... doesn't matter... Because I want to
make the user be able to modify the settings
by changing values inside the file rather than recompiling the program...
Thanks again bro
FroglegRank #1,020 · 1.9K reputationPosted Jan 24, 2011, 5:21 PM EST
'WindowsFormsApplication2.Properties.Settings.Default.myString;
It does save automatically as an xml file - usually in Users\userName\Appdata\Local
Sam HobbsRank #107 · 20.5K reputationPosted Jan 25, 2011, 9:19 AM EST
thiago costaRank #6,113 · 276 reputationPosted Jan 25, 2011, 2:12 PM EST
BUT now I have a problem...
I made that code execute at the Form Load... ok ?...
I made the name be myString, type is string, and the falue is ftp ..
Then I tryed
textBox1.Text = myString; it didn't work .. said myString didnt exist ... what am I doing wrong?
Sam HobbsRank #107 · 20.5K reputationPosted Jan 25, 2011, 3:25 PM EST
FroglegRank #1,020 · 1.9K reputationPosted Jan 25, 2011, 7:24 PM EST
textBox1.Text = WindowsFormsApplication2.Properties.Settings.Default.myString;
When referring to a saved setting it always requires the settings prefix = NameOfProject.Properties.Settings.Default.
Sam HobbsRank #107 · 20.5K reputationPosted Jan 25, 2011, 8:00 PM EST
where propname is the name of the setting. I have never needed to qualify using the project name. I assume that the project name is the namespace name and if the code is in the project's namespace then it is not necessary to specify it.
FroglegRank #1,020 · 1.9K reputationPosted Jan 25, 2011, 8:07 PM EST
Just a habit - probably not a good one
thiago costaRank #6,113 · 276 reputationPosted Jan 25, 2011, 8:28 PM EST
All I am trying to do, is to read a string, from the external file ... and once i get this working, I will be able to test some more and do more...
so, in your example above, the name was myString ...
I did go to the solution's properties, Settings NAME= myString TYPE=string SCOPE=user VALUE=ftp://server
So I thougt by doing that, the string myString would have the value of ftp://server
... but I guess not
I also checked under appdata/local there was no xml files generated...
Am I doing something wrong guys ? ...
All I wanna do is really make it so I can load / save settings to a file ...
I don't know, for example, if the user wants to save his ftp address, so that he doesn't have to type it in everytime...
This is my code.
private void BTNstart_Click_1(object sender, EventArgs e)
{
string file;
file = TBuemail.Text + ".txt";
string ftp;
ftp = "ftp://174.1.1.1/public_html/super3/" + TBuemail.Text + ".txt";
StreamWriter SR1;
SR1 = File.AppendText(file);
SR1.WriteLine(TBuemail.Text);
SR1.WriteLine(TBupw.Text);
SR1.Close();
UploadFile(file, ftp, "quadaxial", "3zxV3rbEs!NOploXultra!");
if (TBuemail.Text != TBvemail.Text)
{
}
else
{
}
}
In the case above, I would want the string ftp to be in an external file... xml or ini
Guys, thanks 100000 times for the attention, I am really stuck on this problem ..
Thanks a bunch guys.
thiago costaRank #6,113 · 276 reputationPosted Jan 25, 2011, 8:43 PM EST
THanks man !
Thankssssss
thiago costaRank #6,113 · 276 reputationPosted Jan 25, 2011, 8:48 PM EST
The label has a value,
I did type something in the myString ... and pressed the button nothing happens !
Maybe is it because that code is not compatible with Visual Studio 2010 ?
If you have teamviewer,
the ID is 265 065 818
the password is yj8k86
FroglegRank #1,020 · 1.9K reputationPosted Jan 25, 2011, 8:53 PM EST
Don't alter that- start the program and type in the textbox and click button1
It saves while your program is running
thiago costaRank #6,113 · 276 reputationPosted Jan 25, 2011, 8:59 PM EST
FROGLEG !!!!!
THANKS MAN !!!!!
IT WORKS !!!!!!!!!!!!!!!!!!!!!!!!!!!
Very nicely done !!!
Thank you so much man !
I have a question ...
Thanks man ! Thank you
It created a .config file ...
But I don't see the value being saved there...
Where does it save the value ?
BROTHER !!!!!! Thank you ! ... Now this code will lead me to some study thanks to you..
Thanks again frogleg
----Edit----
Sorry for getting excited bro ... but this means a lot to me...
Thanks again
FroglegRank #1,020 · 1.9K reputationPosted Jan 25, 2011, 9:02 PM EST
thiago costaRank #6,113 · 276 reputationPosted Jan 25, 2011, 9:03 PM EST
But sometimes on my laptop I run XP x86 sp3
thiago costaRank #6,113 · 276 reputationPosted Jan 25, 2011, 9:05 PM EST
C:\Users\X4-ULTRA\AppData\Local\NewSettings\NewSettings.exe_Url_zgruhibrqgcuwv2wdgwvzcbv3h351euo\1.0.0.0
Hey bro, can I ask you another question ? ...
Is there a way to encrypt this file in case I want to put a password in it?
--EDIT--
---Forget it bro I gave you enough trouble in this already !
I will save this question for another time :D
FroglegRank #1,020 · 1.9K reputationPosted Jan 25, 2011, 9:14 PM EST
That is why I created a default value
Have a look at this
http://www.codeproject.com/KB/security/ProtectedConfigWinApps.aspx
thiago costaRank #6,113 · 276 reputationPosted Jan 25, 2011, 9:20 PM EST
Thank you so much man, ...
I don't know how to thank you.