Pavan Kadambari Pavan Kadambari - 1 year ago 125
C# Question

How to create a text file name with textbox value?

I'm new to C#, I want to create a file with extension

and file name as with first three characters of textbox value.I am creating the file but i dont now how to store the file in the required destination for example c:\ Documents\ION.please help me.
Thank You For reading this...

private void button1_Click(object sender, EventArgs e)
button1.Text = "Create_File";

string fileName = textBox1.Text.Substring(0, 3) + ".txt";



Answer Source

Thank U guys ,with all Your help I solved it

 private void button2_Click(object sender, EventArgs e)
        button2.Text = "SAVE";      
        var files = Directory.GetFiles(@"C:\\Users\\Apple\\Desktop\\proj").Length;
        string fileName = textBox1.Text.Substring(0, 3) + -+ ++files + ".txt";
        string path2 = Path.GetFullPath("C:\\Users\\Apple\\Desktop\\proj");
        string docPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
        string var = Path.Combine(docPath, path2);
        string var1 = Path.Combine(var, fileName);
        using (StreamWriter writer = new StreamWriter(var1))
            string var6 = textBox1.Text;
            string var7 = "                 ";
            string var8 = textBox2.Text;

            string var9 = string.Concat(var6, var7, var8);


        MessageBox.Show("File created");


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download