FileStream to save file then immediately unlock in C# ?

Posted by aron on Stack Overflow See other posts from Stack Overflow or by aron
Published on 2010-04-19T20:00:21Z Indexed on 2010/04/19 20:03 UTC
Read the original article Hit count: 635

Filed under:
|
|
|

Hello, I have this code that saves a pdf file.

FileStream fs = new FileStream(SaveLocation, FileMode.Create);
            fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
            fs.Flush();
            fs.Close();

It works fine. However sometimes it does not release the lock right away and that causes file locking exceptions with functions run after this one run.

Is there a ideal way to release the file lock right after the fs.Close()

thanks!

© Stack Overflow or respective owner

Related posts about filelock

Related posts about locking