By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,213 Members | 1,086 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,213 IT Pros & Developers. It's quick & easy.

Change filename of StreamWriter?

P: n/a

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);
Perform some more operations and write data to StreamWriter }


Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
> (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" <> wrote in message news:<VR********************>... 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!
Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.