c# How to create a button to save/open .txt file from Richtextbox tool without save/open filedialog with a custom filename written in textbox by finding/creating the files in one directory
im a beginner and sorry with my english
savebutton, so first of all i want it create a folder for all the .txt files stored,the folder called "
Faktur" its ok if its already exist and i want it created in exe's directory after installation, and it saves
without savefileDialog
loadbttn, and when loadbutton pressed it enter the folder
Faktur and automatically find the filename that written in the txtidstruk.Text
without openfileDialog
sorry if its too much to ask can someone help me please.. im appreciate all helps thanks
What I have tried:
Savebutton
private void tbsave_Click(object sender, EventArgs e)
{
SaveFileDialog savefile = new SaveFileDialog();
savefile.RestoreDirectory = true;
savefile.InitialDirectory = "e:\\faktur";
savefile.FileName = String.Format("{0}.txt", txtidstruk.Text);
savefile.DefaultExt = "*.txt*";
savefile.Filter = "TEXT Files|*.txt";
if (savefile.ShowDialog() == DialogResult.OK)
{
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(savefile.FileName))
sw.WriteLine(rtfReceipt.Text);
}
Loadbutton
private void tbOpen_Click(object sender, EventArgs e)
{
OpenFileDialog openFile = new OpenFileDialog();
openFile.InitialDirectory = "e:\\faktur";
openFile.Filter = "text Files (*.txt)|*.txt|All files (*.*)|*.*";
openFile.FileName = String.Format("{0}.txt", txtidstruk.Text);
if (openFile.ShowDialog() == DialogResult.OK)
rtfReceipt.LoadFile(openFile.FileName, RichTextBoxStreamType.PlainText);
}