0
Save data In a Custom Extension File And When It Opens A File, Open That Data In Different controls. (C#)
What I need is that my application save data and a datetimepicker (with saveriledialog) and that if it is opened (with openfiledialog) it is written in different textbox
5 Réponses
+ 1
//to open a file with filename from openFileDialog and place the contents of the file in a text box
//https://www.dotnetperls.com/openfiledialog
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK) // Test result.
{
textbox1.Text = File.ReadAllText(openFileDialog1.FileName);
}
//To save a file using filedialog,
1) get the filename
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Text = saveFileDialog1.FileName;
}
2) Save contents in a file
string createText = "Hello and Welcome" + Environment.NewLine;
File.WriteAllText(saveFileDialog1.FileName, createText);
+ 1
And I save that Variable Into A File?
0
Yeah but how can I do that some parts of the text put into different textbox?
0
Make a variable and concatenate the data of all the textboxes.
string result= "";
result = textbox1.text + textbox2.text + textbox3.text;
0
string result= "";
result = textbox1.text + textbox2.text + textbox3.text;
File.WriteAllText(saveFileDialog1.FileName, result);
http://www.java2s.com/Tutorials/CSharp/System.IO/File/C_File_WriteAllText_String_String_.htm