Change filename of StreamWriter?

L

Lars Hansen

Hi

This is probably pretty basic, but I have a problem with the access-level
(local variable), when creating a new StreamWriter. I am trying to write
some price information to a textfile - which works fine. But due to the
dataamounts involved I now need to split it out to several files.

The actions I am taking are:

- create the first file
- write data (pricelists) to file
- when number of pricelist = maxAllowed create new file with filename +1
- write the next data to the new file

But when I create a new StreamWriter in my textblock, I am creating a local
variable. I tried instead to set a static StreamWriter + FileInfo with
nullvalues. In my IF-block I assigned the FileInfo to the StreamWriter -
ie. sw = fi.CreateText(). But then I am not able (AFAIK) to set the file as
Unicode - which is a prerequisite.

My program structure is: (I know that the StreamWriters won´t work this way)

while ((line = customerList.ReadLine())!=null)
{
if(priceListCount==1 & fileCount==1)
{
outPriceFileName = "c:\\test\\out.txt";
StreamWriter outStream = new
StreamWriter(outPriceFileName, false, System.Text.Encoding.Unicode);
}
else if(priceListCount=maxAllowed)
{
outPriceFileName = "c:\\test\\out" + fileCount + ".txt";
StreamWriter outStream = new
StreamWriter(outPriceFileName, false, System.Text.Encoding.Unicode);
fileCount++
}
Perform some more operations and write data to StreamWriter }

Regards

Lars
 
C

Chris Hornberger

(hint: declare local variable and assign value of local var to global -
maybe I should patent that and sue someone)

Keep thinking like that and you'll be running a west-coast software
company before you know it :)

Lars Hansen said:
Went shopping
Had something to eat
Got back and looked at the code

Realized that my question was somewhat stupid

Glad to see walking away from the problem fixed it for you. I find
myself doing that sometimes. Just leave. Walk away. Clear the head.
Come back fresh and ready to rock!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top