public DocumentCommandResult TrySaveAsNewDocument(string documentName, out string newDocumentUrl) { newDocumentUrl = null; Item newDocument = new Item() { Name = documentName, IsFolder = false }; if (!IsDocumentEditingAllowed(newDocument)) { return(DocumentCommandResult.NotSupportedFormat); } Item document = GetDocumentInCurrentFolder(documentName); if (document != null) { return(DocumentCommandResult.DocumentAlreadyExists); } newDocument.Owner = DocumentsApp.User.CurrentUser; newDocument.ParentItem = CurrentDocument.ParentItem; newDocument.CreationTime = DateTime.UtcNow; newDocument.LastAccessTime = DateTime.UtcNow; newDocument.LastWriteTime = DateTime.UtcNow; byte[] newDocumentData; string sourceDocIdForEditor = GetDocumentIdForEditor(CurrentDocument); IDocumentInfo sourceDocInfo = DocumentManager.FindDocument(sourceDocIdForEditor); if (IsRichEditDocument(CurrentDocument)) { RichEditDocumentInfo richEditDocInfo = sourceDocInfo as RichEditDocumentInfo; DevExpress.XtraRichEdit.DocumentFormat richEditFormat = GetRichEditDocumentFormat(newDocument); newDocumentData = richEditDocInfo.SaveCopy(richEditFormat); } else if (IsSpreadsheetDocument(CurrentDocument)) { SpreadsheetDocumentInfo spreadsheetDocInfo = sourceDocInfo as SpreadsheetDocumentInfo; DevExpress.Spreadsheet.DocumentFormat spreadsheetFormat = GetSpreadsheetDocumentFormat(newDocument); newDocumentData = spreadsheetDocInfo.SaveCopy(spreadsheetFormat); } else { throw new Exception("Incorrect document format."); } newDocument.Content = DataService.CreateBinaryContent(newDocumentData); DataService.AddItem(newDocument); DataService.SaveChanges(); string newDocumentPath = GetPathForDocumentInCurrentFolder(documentName); newDocumentUrl = GetDocumentEditorRequestUrl(newDocumentPath); return(DocumentCommandResult.OK); }
public static void LoadDocumentEx(this IRichEditControl richEdit, Stream stream) { DevExpress.XtraRichEdit.DocumentFormat currentFormat = AutoDetermineDocumentFormat(stream); stream.Seek(0, SeekOrigin.Begin); richEdit.InnerControl.LoadDocument(stream, currentFormat); }