protected void he_Init(object sender, EventArgs e)
    {
        ASPxHtmlEditor htmlEditor = sender as ASPxHtmlEditor;
        GridViewDataItemTemplateContainer container = htmlEditor.NamingContainer as GridViewDataItemTemplateContainer;
        string rtfText = container.Grid.GetRowValues(container.VisibleIndex, "RtfContent").ToString();

        byte[] byteArray = Encoding.ASCII.GetBytes(rtfText);
        using (MemoryStream ms = new MemoryStream(byteArray)) {
            htmlEditor.Import(HtmlEditorImportFormat.Rtf, ms, false, ContentFolder);
        }
    }
        protected void Page_Load(object sender, EventArgs e)
        {
            // Opening Document
            var documentID = Request.QueryString["id"];
            int itemID     = -1;

            int.TryParse(documentID, out itemID);
            var item           = Utils.CurrentDataProvider.GetDocumentById(itemID);
            var data           = item.Content.Data;
            var documentFormat = GetDocumentFormat(data, item.Name);

            // View Mode emulation
            if (string.IsNullOrEmpty(Request.QueryString["edit"]))
            { // is view mode?
                using (MemoryStream ms = new MemoryStream())
                {
                    ms.Write(data, 0, data.Length);
                    ms.Position = 0;

                    string documentPreviewFilesFolder = Utils.GetDocumentPreviewFilesFolderById(itemID);
                    string documentPreviewFileName    = documentPreviewFilesFolder + @"\preview";
                    string html;
                    if (Directory.Exists(documentPreviewFilesFolder) && File.Exists(documentPreviewFileName))
                    {
                        html = File.ReadAllText(documentPreviewFileName);
                    }
                    else
                    {
                        ASPxHtmlEditor htmlEditor = new ASPxHtmlEditor();
                        htmlEditor.Import(GetHtmlEditorImportFormat(documentFormat), ms, true, documentPreviewFilesFolder);
                        html = htmlEditor.Html;
                        if (!Directory.Exists(documentPreviewFilesFolder))
                        {
                            Directory.CreateDirectory(documentPreviewFilesFolder);
                        }
                        File.WriteAllText(documentPreviewFileName, html);
                    }
                    viewer.InnerHtml = html;
                }

                viewerWrapper.Visible = true;
                richEdit.Visible      = false;
            }
            else
            {
                richEdit.Open(documentID + "&" + Guid.NewGuid().ToString(), () => data);
                viewerWrapper.Visible = false;
            }
        }