Using StreamWriter...... Help Guys [modified]
-
I am using the following Text/StreamWriter process to write to a Text file: { TextWriter tr=new StreamWriter("C:/Streamfile.txt"); tr.WriteLine("This line has been written by the StreamWriter process"); tr.Close(); } However, if I want to write to a VBScript file or a Jscript file, then what manipulation will I have to do to the above code, such that I am able to write to those script files? Please help me guys. Thank you, Rajdeep.NET :sigh:
modified on Tuesday, April 7, 2009 2:38 PM
-
I am using the following Text/StreamWriter process to write to a Text file: { TextWriter tr=new StreamWriter("C:/Streamfile.txt"); tr.WriteLine("This line has been written by the StreamWriter process"); tr.Close(); } However, if I want to write to a VBScript file or a Jscript file, then what manipulation will I have to do to the above code, such that I am able to write to those script files? Please help me guys. Thank you, Rajdeep.NET :sigh:
modified on Tuesday, April 7, 2009 2:38 PM
-
I am using the following Text/StreamWriter process to write to a Text file: { TextWriter tr=new StreamWriter("C:/Streamfile.txt"); tr.WriteLine("This line has been written by the StreamWriter process"); tr.Close(); } However, if I want to write to a VBScript file or a Jscript file, then what manipulation will I have to do to the above code, such that I am able to write to those script files? Please help me guys. Thank you, Rajdeep.NET :sigh:
modified on Tuesday, April 7, 2009 2:38 PM
If I have understood you correctly, you want to generate a VBscript or Jscript file from within your C# app. All you have to do is write the contenst of the fiel exactly like you would in notepad or whatever. You would probably want to change the file extension (to .vbs for the VBScript file), but thats all, there is nothing special about it.
Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP
-
If I have understood you correctly, you want to generate a VBscript or Jscript file from within your C# app. All you have to do is write the contenst of the fiel exactly like you would in notepad or whatever. You would probably want to change the file extension (to .vbs for the VBScript file), but thats all, there is nothing special about it.
Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP
Try using this code:
private void btnSave\_Click(object sender, EventArgs e) { FileDialog salvareFisier = new SaveFileDialog(); salvareFisier.Filter = "Text files (\*.txt)|\*.txt"; if (salvareFisier.ShowDialog() == DialogResult.OK) { FileStream fisier = new FileStream(salvareFisier.FileName, FileMode.Create, FileAccess.Write); addText(fisier,"your \_text \_ here "); addText(fisier, "\\r\\n"); fisier.Close(); } else MessageBox.Show("Data has not been saved"); } public static void addText(FileStream f, string valoare) { byte\[\] info = UTF8Encoding.Default.GetBytes(valoare); f.Write(info, 0, info.Length); }
Regards, Alex