/// <summary> /// Open a file, create a view-model and it to the collection of document view-models. /// </summary> public void OpenFile(string filePath) { try { var fileContent = File.ReadAllText(filePath); var newDocumentViewModel = new TextFileDocumentViewModel(filePath, fileContent, false); this.Documents.Add(newDocumentViewModel); } catch (Exception ex) { DialogProvider.ErrorMessage("Failed to open document " + filePath + "\n" + "Exception occurred:\n" + ex.ToString()); } }
/// <summary> /// Save the specified document to the specified filepath. /// </summary> public void SaveFile(TextFileDocumentViewModel document, string newFilePath) { try { File.WriteAllText(newFilePath, document.Text); document.FilePath = newFilePath; document.IsModified = false; } catch (Exception ex) { DialogProvider.ErrorMessage("Failed to save document " + newFilePath + "\n" + "Exception occurred: \n" + ex.ToString()); } }