How do I create a program that creates a file in C#?

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2008
Posts: 29
Reputation: vandenzergen is an unknown quantity at this point 
Solved Threads: 0
vandenzergen's Avatar
vandenzergen vandenzergen is offline Offline
Light Poster

How do I create a program that creates a file in C#?

 
0
  #1
Dec 12th, 2008
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...
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 584
Reputation: Murtan is a jewel in the rough Murtan is a jewel in the rough Murtan is a jewel in the rough Murtan is a jewel in the rough 
Solved Threads: 94
Murtan Murtan is offline Offline
Posting Pro

Re: How do I create a program that creates a file in C#?

 
0
  #2
Dec 13th, 2008
It may not be very efficient, but this creates an output file with the one string in it:

  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace FileCreationTesting
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. String test = "This is some sample data\n";
  14. FileStream fh = File.OpenWrite("targetfile.txt");
  15. fh.Write(Encoding.ASCII.GetBytes(test), 0, Encoding.ASCII.GetByteCount(test));
  16. fh.Close();
  17. }
  18. }
  19. }
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,977
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 288
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: How do I create a program that creates a file in C#?

 
0
  #3
Dec 13th, 2008
FileStream fs = File.Create(@"C:\MyFiles\Test.txt"); will create a file Test.txt in the directory MyFiles on the C-drive.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 3
Reputation: Georgerxz is an unknown quantity at this point 
Solved Threads: 0
Georgerxz Georgerxz is offline Offline
Newbie Poster

Re: How do I create a program that creates a file in C#?

 
0
  #4
Dec 13th, 2008
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>
Last edited by happygeek; Dec 13th, 2008 at 6:09 pm. Reason: URL snipped
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,240
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 542
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: How do I create a program that creates a file in C#?

 
0
  #5
Dec 13th, 2008
Use OpenFileDialog
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,977
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 288
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: How do I create a program that creates a file in C#?

 
0
  #6
Dec 13th, 2008
Originally Posted by jbennet
Use OpenFileDialog
IMHO you can create a folder a map a directory with OpenFileDialog, but no file...
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,240
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 542
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: How do I create a program that creates a file in C#?

 
0
  #7
Dec 13th, 2008
you can
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 29
Reputation: vandenzergen is an unknown quantity at this point 
Solved Threads: 0
vandenzergen's Avatar
vandenzergen vandenzergen is offline Offline
Light Poster

Re: How do I create a program that creates a file in C#?

 
0
  #8
Dec 20th, 2008
Thank you very much everyone!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC