help exporting text
hey guys i need some help,
i have a text box and a button next to it
i want people to type in stuff into the text box then press the button, when they press the button the stuff in the text box will be saveed as a lua file (a lua file is just a txt filw with a different extension)
Scott LyslePosted Mar 16, 2007, 6:46 PM
using
System;using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace
TextBoxToFile{ public partial class Form1 : Form
{ public Form1()
{
InitializeComponent();
}
private void tsbSave_Click(object sender, EventArgs e){
saveFileDialog1.Title = "Open LUA File";
saveFileDialog1.Filter = "LUA | *.lua";
saveFileDialog1.DefaultExt = "lua";
saveFileDialog1.FileName = "";
saveFileDialog1.ShowDialog(); if (saveFileDialog1.FileName == "")
return;
StreamWriter sw;
FileStream fs;
string fName = saveFileDialog1.FileName;
fs = new FileStream(fName, FileMode.OpenOrCreate);
sw = new StreamWriter(fs);
sw.Write(txtContent.Text);
sw.Close();
fs.Close();
} private void tsbOpen_Click(object sender, EventArgs e)
{
openFileDialog1.Title = "Open LUA File";
openFileDialog1.Filter = "LUA | *.lua";
openFileDialog1.DefaultExt = "lua";
openFileDialog1.FileName = "";
openFileDialog1.ShowDialog(); if (openFileDialog1.FileName == "")
return;
FileStream fs = new FileStream(openFileDialog1.FileName,
FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
txtContent.Text = sr.ReadToEnd();
sr.Close();
fs.Close();
}
}
}