using (var file = new FileStream(filePath,FileMode.OpenOrCreate,FileAccess.Write,FileShare.None)) { xmlDoc.Save(file); }