protected override bool HandleCommand(Command command) { bool flag = false; if ((command.CommandGroup == typeof(WebCommands)) && (command.CommandID == 250)) { StringWriter output = new StringWriter(); HtmlFormatter formatter = new HtmlFormatter(); base.ClearSelection(); formatter.Format(this.Text, output, new HtmlFormatterOptions(' ', 4, 80, true)); output.Flush(); base.SetText(output.ToString(), true); flag = true; } if (!flag) { flag = base.HandleCommand(command); } return flag; }
public string SaveHtml() { if (!this.IsCreated) { throw new Exception("HtmlControl.SaveHtml : No HTML to save!"); } string input = string.Empty; try { this.OnBeforeSave(); Interop.IHTMLDocument2 mSHTMLDocument = this._site.MSHTMLDocument; if (this._fullDocumentMode) { //NOTE: �л������ģʽ�����������������, ʹ��System.Runtime.InteropServices.ComTypes�µ���ͽṹ�������� // �滻Interop.IStreamΪSystem.Runtime.InteropServices.ComTypes.IStream IntPtr ptr; Interop.IPersistStreamInit init = (Interop.IPersistStreamInit)mSHTMLDocument; System.Runtime.InteropServices.ComTypes.IStream pStream = null; Interop.CreateStreamOnHGlobal(Interop.NullIntPtr, true, ref pStream); init.Save(pStream, 1); //Interop.STATSTG pstatstg = new Interop.STATSTG(); System.Runtime.InteropServices.ComTypes.STATSTG pStat = new System.Runtime.InteropServices.ComTypes.STATSTG(); pStream.Stat(out pStat, 1); int cbSize = (int)pStat.cbSize; byte[] destination = new byte[cbSize]; Interop.GetHGlobalFromStream(pStream, out ptr); IntPtr source = Interop.GlobalLock(ptr); if (!(source != Interop.NullIntPtr)) { goto Label_010B; } Marshal.Copy(source, destination, 0, cbSize); Interop.GlobalUnlock(ptr); StreamReader reader = null; try { reader = new StreamReader(new MemoryStream(destination), Encoding.Default); input = reader.ReadToEnd(); goto Label_010B; } finally { if (reader != null) { reader.Close(); } } } Interop.IHTMLElement body = mSHTMLDocument.GetBody(); if (body != null) { input = this.GetContentElement(ElementWrapperTable.GetWrapper(body, this)).InnerHtml; } } catch (Exception) { input = string.Empty; } finally { this.OnAfterSave(); } Label_010B: if (input == null) { input = string.Empty; } HtmlFormatter formatter = new HtmlFormatter(); StringWriter output = new StringWriter(); formatter.Format(input, output, new HtmlFormatterOptions(' ', 4, 80, true)); return output.ToString(); }