473,406 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Multiple File Names Created From One Streamwriter

TC
I need the ability to create a series of individual files via one
Streamwriter (one at a time). Currently I have an application that is
writing out all of the data to one text file. The user has requested the
data is to be broken into individual files (could be from one to many depend
on the volume of data). This could lead to many separate files being
created. How do I write to a new file name using “StreamWriter sr =
File.CreateText(FileName)” ?

Thanks
May 15 '06 #1
2 4753
TC,

All you have to do is create a new FileStream, and then pass that to a
new StreamWriter.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"TC" <TC@discussions.microsoft.com> wrote in message
news:49**********************************@microsof t.com...
I need the ability to create a series of individual files via one
Streamwriter (one at a time). Currently I have an application that is
writing out all of the data to one text file. The user has requested the
data is to be broken into individual files (could be from one to many
depend
on the volume of data). This could lead to many separate files being
created. How do I write to a new file name using "StreamWriter sr =
File.CreateText(FileName)" ?

Thanks

May 15 '06 #2
TC <TC@discussions.microsoft.com> wrote:
I need the ability to create a series of individual files via one
Streamwriter (one at a time). Currently I have an application that is
writing out all of the data to one text file. The user has requested the
data is to be broken into individual files (could be from one to many depend
on the volume of data). This could lead to many separate files being
created. How do I write to a new file name using “StreamWriter sr =
File.CreateText(FileName)” ?


You need to flush the old stream writer when you're done with one file
and create a new instance via File.CreateText(string), as you indicate.

An idea: write a loop and name the files in sequence, for example:

---8<---
int fileNumber = 1;
while (!someWork.IsFinished)
{
using (TextWriter writer =
File.CreateText(string.Format("File{0}.txt", fileNumber)))
foreach (string someStuff in someWork)
writer.Write(someStuff);
++fileNumber;
}
--->8---

Without knowing more about what exactly your problem is, I think it is
difficult to help you.

-- Barry
May 15 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Stephen Cook | last post by:
Having worked through the problems around enabling the document function using an XmlUrlResolver I started work on building a useful class to hide the intricacies. Trying to generalise the process...
2
by: Marge Inoferror | last post by:
Visual C#... I'd like to save some settings that are in integers and then save some lists of file names. I'm just starting off (as you can tell - no doubt.). I'm starting by trying to save...
9
by: ALI-R | last post by:
Hi,, I have two questions : 1) Is it mandatory that config file of a desktop application must be App.config 2) Is it possible to update config file in your code?? thanks for your help. ALI
4
by: HNguyen | last post by:
Hi, I have a Web application in ASP.NET. My Application allows the users upload files into the server after checking their user names and passwords. For each transaction, the Web program will...
2
by: Bruce Wiebe | last post by:
hi all im having a problem accessing a text file on my hard disk after ive created it and added some text to it it would appear that the file is still locked. What happens is this i have...
6
by: Don | last post by:
I'm having problems working with a streamwriter object. After closing the streamwriter and setting it to Nothing, I try to delete the file it was writing to, but I always get the following error...
2
by: sameer | last post by:
Hi, My very simple application VB.NET Visual Studio 2003 console application uses a log file to write some text to it. I am using StreamWriter object to create and open and then append text to...
0
by: amitp | last post by:
Can anyone help me out in this? I want to append multiple RTF file into one RTF file. I tried using 'streamwriter', the resulting file size becomes big and when i open it, it is the original i.e the...
1
by: David Veeneman | last post by:
I have a maddening problem that I hope someone can help with. I have some code that writes temporary documents to the data folder of my web site. On one document, I keep getting an error "The...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.