You are viewing our Forum Archives. To view or take place in current topics click here.
Simple C# Programming Help
Posted:
Simple C# Programming HelpPosted:
Status: Offline
Joined: Jul 26, 201212Year Member
Posts: 357
Reputation Power: 19
Status: Offline
Joined: Jul 26, 201212Year Member
Posts: 357
Reputation Power: 19
My coding is all correct, no errors. I'm having an issue with my text saving to a .txt with spacing. If anyone can help me i would appreciate it.
Thanks in advance
private void button3_Click(object sender, EventArgs e)
{
string file = "";
SaveFileDialog ofd = new SaveFileDialog();
ofd.InitialDirectory = "c:\\";
ofd.Filter = "Text Files (*.txt)|*.txt";
ofd.FilterIndex = 2;
ofd.RestoreDirectory = true;
DialogResult dr = ofd.ShowDialog();
if (dr == System.Windows.Forms.DialogResult.OK)
{
file = ofd.FileName;
textBox1.Text = file;
System.IO.File.WriteAllText(file, notes.Text);
}
}
Thanks in advance
#2. Posted:
Status: Offline
Joined: May 26, 201311Year Member
Posts: 491
Reputation Power: 22
Use something like:
var dr = saveFileDialog1.ShowDialog();
if( dr == DialogResult.OK )
{
using(var SaveFile = new StreamWriter(saveFileDialog1.FileName))
{
SaveFile.WriteLine(textBox1.Text);
issaved = true;
}
}
- 0useful
- 0not useful
#3. Posted:
Status: Offline
Joined: Oct 07, 201014Year Member
Posts: 247
Reputation Power: 9
Status: Offline
Joined: Oct 07, 201014Year Member
Posts: 247
Reputation Power: 9
stick a @ in front of the " in the string location of the file, you will have to use an absolute path for it though instead of a relative path. the @ escapes the string automatically so string = "C:\\some path", an invalid path, becomes string = @"C:\\some path" a valid path
- 0useful
- 0not useful
#4. Posted:
Status: Offline
Joined: Jul 26, 201212Year Member
Posts: 357
Reputation Power: 19
Status: Offline
Joined: Jul 26, 201212Year Member
Posts: 357
Reputation Power: 19
ODST_107 wrote stick a @ in front of the " in the string location of the file, you will have to use an absolute path for it though instead of a relative path. the @ escapes the string automatically so string = "C:\\some path", an invalid path, becomes string = @"C:\\some path" a valid pathDidn't work bud, but thanks for trying
Since it adds the spaces when I open the program then ill just make a special file.
- 0useful
- 0not useful
#5. Posted:
Status: Offline
Joined: Aug 29, 201212Year Member
Posts: 652
Reputation Power: 27
Status: Offline
Joined: Aug 29, 201212Year Member
Posts: 652
Reputation Power: 27
Im a little confused on what you are trying to do, if you make it a little more clear i might be able to help
- 1useful
- 0not useful
You are viewing our Forum Archives. To view or take place in current topics click here.