using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None)) { fs.SetLength(sizeInMB * 1024 * 1024); }