/// <summary> /// Activate the editor /// </summary> /// <param name="withUI">Activates the UI of the control immediately after start up.</param> /// <remarks> /// UI activation means that the caret appears immediately after the designer surface appears, whether or not the /// control has the focus. /// </remarks> public void ActivateMSHTML(bool withUI) { try { this.WithUI = withUI; Interop.RECT r = EditorRect; int result = OleDocument.DoVerb((int)Interop.OLE.OLEIVERB_UIACTIVATE, Interop.NullIntPtr, this, 0, EditorHandle, r); if (result == Interop.S_OK) { this.htmlEditor.NeedActivation = false; } else { throw new ApplicationException("Activate UI in ActivateMSHTML failed with result " + result); } htmlEditor.AddEditDesigner(this); } catch (Exception e) { Debug.Fail(e.ToString()); } }
public static string GetFormatFile(Stream stmFile) { try { var br = new BinaryReader(stmFile); byte[] start = null; if (stmFile.Length < 8) { return(string.Empty); } start = br.ReadBytes(8); if (Encoding.ASCII.GetString(start).StartsWith("%PDF-")) { return("pdf"); } var magic_number = new byte[8] { 0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1 }; var isdoc = true; for (var i = 0; i < magic_number.Length; i++) { if (start[i] != magic_number[i]) { isdoc = false; break; } } if (isdoc) { var doc = new OleDocument(stmFile); if (doc.isValid()) { doc.readMSAT(); doc.readSAT(); doc.readSSAT(); doc.readDir(); if (doc.OpenStream("WordDocument") != null) { return("doc"); } if (doc.OpenStream("Workbook") != null) { return("xls"); } if (doc.OpenStream("PowerPoint Document") != null) { return("ppt"); } } } ZipFile z = null; try { z = ZipFile.Read(stmFile); foreach (var s in z.EntryFileNames) { if (s.StartsWith("word")) { return("docx"); } if (s.StartsWith("xl")) { return("xlsx"); } if (s.StartsWith("ppt")) { return("pptx"); } } return("odt"); } catch { return(String.Empty); } finally { z.Dispose(); } } catch { return(string.Empty); } }