WriteAllText overwrites the file. Butyou are using StringBuilder and it
looks like you are appending new and new text to the stringbuilder
somewhere...
Just try to replace WriteAllText method with AppendAllText, I think your
data will be duplicated each time you use it...

2009/10/6 Benj Nunez <[email protected]>

>
> Hello everyone,
>
>
> I would just like to share with you my observation with the use of the
> File.WriteAllText().
> I have code like this:
>
> public bool dumpToFile(ref StringBuilder AData, String AFileNameStr)
> {
>   ...
>            string AppPath = Application.StartupPath;
>
>            AppPath += "\\";
>            try
>            {
>                File.WriteAllText(@AppPath + AFileNameStr,
> AData.ToString());
>                IsOk = true;
>            }
>            catch (System.ArgumentNullException)
>            {
>                throw;
>            }
>
>            ...
> }
>
>
> I'm expecting that every time I run the dumpToFile() method  it
> overwrites the file
> that already exists. Well, apparently in my case it did not (although
> the documentation
> says it can.).
>
> Any comments on this? I'm aware that I can use StreamWriter as a
> substitute. Your inputs
> are welcome.
>
>
>
>
>
>

Reply via email to