Jaap,
You won't be able to get it. Until Vista is released, you won't be able
to incorporate transactional behavior into file operations.
However, I do think you should order your approach somewhat differently.
I would open the new file stream and write the contents, then open the old
stream and copy the contents over. There is no reason to keep the current
files contents in memory while you write the new content (unless you need it
for some other reason).
When Vista comes out, you should be able to use a FileStream in a
TransactionScop e and you should be able to perform your file operations as
part of a transaction. If it is not built into the FileStream, you will
always be able to drop down to the API level to perform transactional work.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard. caspershouse.co m
"japi" <jv******@gmail .comwrote in message
news:11******** **************@ i3g2000cwc.goog legroups.com...
Hi,
i would like to know what approach i should use to insert (not append)
a line of text to the begin of an existing text file.
My current approach works, but i am afraid of loosing data if an
exceptions is thrown somewhere in between the process.
My current approach:
1. read current contents of the file
2. create a filestream object (with FileMode.Create ) wrapped in a
streamwriter object
3. write the new line of text
4. write the content that was read in step 1
im looking for a more transactional approach.
Thanks in advance.
Cheers,
Jaap