public void SaveItems() { var today = DateTime.Now.Date; var newFileName = GetFileName(today, FileNameType.ForSaving); using (var stream = new FileStream(newFileName, FileMode.Create)) { var writer = new XmlSerializer(typeof(ObservableCollection<WorkItem>)); var items = new ObservableCollection<WorkItem>(); var factory = new ViewModelFactory(); foreach (var item in factory.ConvertBack<WorkItem>(WorkItems)) { items.Add(item); } writer.Serialize(stream, items); } var fileName = GetFileName(today, FileNameType.Default); try { File.Replace(newFileName, fileName, null); } catch (FileNotFoundException) { File.Move(newFileName, fileName); } }