| | |
How do I create a program that creates a file in C#?
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
Hello everyone, I'm having a problem of creating a program that provides a functionality of creating its own file, saving its own file, and reopening its own file just like the functionality of the other windows application like MSWord, MSExcel, etc.,
Please everyone, I really need to know about it... I know that programming languages have this kind of capabilities but I don't know where to find it, please everyone...
Please everyone, I really need to know about it... I know that programming languages have this kind of capabilities but I don't know where to find it, please everyone...
•
•
Join Date: May 2008
Posts: 584
Reputation:
Solved Threads: 94
It may not be very efficient, but this creates an output file with the one string in it:
c# Syntax (Toggle Plain Text)
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; namespace FileCreationTesting { class Program { static void Main(string[] args) { String test = "This is some sample data\n"; FileStream fh = File.OpenWrite("targetfile.txt"); fh.Write(Encoding.ASCII.GetBytes(test), 0, Encoding.ASCII.GetByteCount(test)); fh.Close(); } } }
•
•
Join Date: Dec 2008
Posts: 3
Reputation:
Solved Threads: 0
Following C# program can create the text file on d drive. You can change the path of file to be created.
---------------------------------------------------------------------------
using System;
using System.IO;
class CreateNewFile
{
static void Main(string[] args)
{
TextWriter tw = new StreamWriter("d:\\NewFile.txt");
tw.WriteLine("This is new file i have created");
tw.WriteLine(DateTime.Now);
tw.Close();
}
}
---------------------------------------------------------------------------
GeorgeRxz
<SNIP>
---------------------------------------------------------------------------
using System;
using System.IO;
class CreateNewFile
{
static void Main(string[] args)
{
TextWriter tw = new StreamWriter("d:\\NewFile.txt");
tw.WriteLine("This is new file i have created");
tw.WriteLine(DateTime.Now);
tw.Close();
}
}
---------------------------------------------------------------------------
GeorgeRxz
<SNIP>
Last edited by happygeek; Dec 13th, 2008 at 6:09 pm. Reason: URL snipped
![]() |
Similar Threads
- How do I create a program that creates a file that stores the variables data? (C++)
- Homework help (C++)
- C++ program write and display to file (C++)
- How to save a file to C://+string (C)
- Giving input to a c++ file (Shell Scripting)
- Program Help: Urgent (C)
- I just started Python... (Python)
- file types and main arguments (C)
- turning userinput into a text file (C)
- Help with Java program writing (Java)
Other Threads in the C# Forum
- Previous Thread: C# help please
- Next Thread: How to save the method that I do
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# capturing chat check checkbox client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format forms function gdi+ httpwebrequest image index input install java label libraries list listbox listener loop mandelbrot math mouseclick mysql networking operator path photoshop picturebox pixelinversion post programming radians regex remote remoting richtextbox running... save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






