File.Create Locking File

It’s very handy to use File.Create(“filename.txt”) inside .NET. Specially when doing a quick File.Exists and recreate the missing file using File.Create, but right after creating the file using File.Create, the file was locked. To fix this, the use of Using, or adding a .Dispose after the statement will do the works.

[cc lang=”csharp” escaped=”true”]
using (File.Create(“filename.txt”));//OR File.Create(“filename.txt”).Dispose();

It’s a simple thing, but often forgotten bout it, good to remember again!