Lets say there is a file which is 150 bytes long and I want to truncate the last 16 (or any number) of it from the end...
Is there any other way to do it than re writing the complete file?
UPDATE: The SetLength should do the thing, but unfortunately NotSupportedException is thrown
using (FileStream fsFinalWrite = new FileStream(FileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
{
fsFinalWrite.Seek(16, SeekOrigin.End);
fsFinalWrite.Write(SwappedBytes, 0, 16);
Debug.WriteLine("fsFinalWrite Can Seek = " + fsFinalWrite.CanSeek);
Debug.WriteLine("fsFinalWrite Can Write = " + fsFinalWrite.CanWrite);
fsFinalWrite.SetLength((long)lengthOfFile);
}
Both print true! But still it throws a NotSupportedException. Anyone know how to handle this?