| View previous topic :: View next topic |
| Author |
Message |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Tue Dec 18, 2007 8:10 am Post subject: [question] help in C# please |
|
|
i'm working at WindowApplication and i wanna create a button for saving.. is there option that allows me to do it??
_________________
Stylo |
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Tue Dec 18, 2007 8:18 am Post subject: |
|
|
| A button to save What?
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Tue Dec 18, 2007 8:28 am Post subject: |
|
|
i'v created textbox to write some things in it and i wanna create a saving button to save what's write inside that textbox
_________________
Stylo |
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Tue Dec 18, 2007 8:33 am Post subject: |
|
|
SaveDialog SD = new SaveDialog();
SaveDialog.ShowDialog();
If I remember correctly.
or it might be SaveFileDialog...
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Tue Dec 18, 2007 8:51 am Post subject: |
|
|
thx symbol but how do i tell him to save a specific info from my TextBox to a File??? and when i try to save the area of file type is empty ( i mean the place with *.txt / All files place) what do i need to do to see it?
_________________
Stylo |
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Tue Dec 18, 2007 8:54 am Post subject: |
|
|
System.IO.File.WriteAllText("FileName.txt",textBox1.text + " " + textBox2.Text);
if you want a new line then use System.IO.Stream if I'm not wrong.
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Tue Dec 18, 2007 9:12 am Post subject: |
|
|
You need System.IO...
But I wouldn't add the whol libary just for that, when you write System.IO.File it uses only the parts needed to use it.
Since I don't have C# here, I'll google some and see if I was right.
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Tue Dec 18, 2007 9:16 am Post subject: |
|
|
i'm using System.IO for other things ofcours so i dont mind to use it...
_________________
Stylo |
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Tue Dec 18, 2007 9:38 am Post subject: |
|
|
| System.IO.File.WriteAllText() works fine...
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Tue Dec 18, 2007 10:22 am Post subject: |
|
|
it's says 'System.IO.File' does not contain a definition for 'WriteAllText'
and when i wanna save file it open the save dialog and i cant choose file name cuz nothing is inside there how can i input values inside??
look picture..
| Description: |
|
| Filesize: |
28.65 KB |
| Viewed: |
8768 Time(s) |

|
_________________
Stylo |
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Tue Dec 18, 2007 10:33 am Post subject: |
|
|
Add extention... you can also add the control from the tool box, go to dialogs and drag Save Dialog to your form, but I prefer doing it the other way with a code.
I think its BlBla.filter = "Executeable files (*.exe) bla bla text lol |*.exe|text lol|*.extention";
BlaBla is the name of the SaveFileDialog.
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Tue Dec 18, 2007 10:43 am Post subject: |
|
|
ok that worked perfectly but i have another problem
look picture..
see the big TextBox..
i wanna write something inside it and when i click save it will open dialog and bla bla... and it will save what i'v writen inside that big TextBox as *.txt / *.exe / or whatever..
| Description: |
|
| Filesize: |
14.06 KB |
| Viewed: |
8763 Time(s) |

|
_________________
Stylo |
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Tue Dec 18, 2007 12:45 pm Post subject: |
|
|
| Code: |
private void Save_Click(object sender, EventArgs e) //Save would be the button name
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.DefaultExt = "txt";
sfd.AddExtension = true;
sfd.FileName = FileName.Text; //Assuming FileName is the name of the textbox with that says "file name here" or whatever
sfd.FileOk += new CancelEventHandler(sfd_FileOk);
sfd.Show();
}
private void sfd_FileOk(object sender, CancelEventArgs e)
{
SaveFileDialog sfd = (SaveFileDialog)sender;
string Path = sfd.FileName.Substring(sfd.FileName.LastIndexOf("\\")+1);
File.WriteAllText(Path, Code.Text); //Assuming that Code is the name of the textbox that has the stuff to be saved in it
}
|
_________________
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Tue Dec 18, 2007 2:03 pm Post subject: |
|
|
i still got problem with the line File.WriteAllText it says 'System.IO.File' does not contain a definition for 'WriteAllText'
and i'm using System.IO
_________________
Stylo |
|
| Back to top |
|
 |
|