Displaying Outlook.msg in an HTMLEditor control on page load

  1. #1

    Displaying Outlook.msg in an HTMLEditor control on page load

    Hello,

    I have been wracking my brain trying to figure this one out. I have a simple HtmlEditor control. My intent is to load an Outlook .msg body content into this editor on page load. The problem I am having is that no matter whether i set the .Text or .Value of the control to the body content, or use .SetValue() in the same manor, the content is not displayed inside the control, but outside of it. Here's my code:

    1.This is the Editor control:
        <ext:HtmlEditor ID="eEmail"  
            runat="server"
            Width="610" 
            Height="505"
            EnableAlignments="false"
            EnableFontSize="false">
        </ext:HtmlEditor>
    2. This is the code behind where i get and set the body content:
            
            Dim outlookApp As New Microsoft.Office.Interop.Outlook.Application
            Dim item = TryCast(outlookApp.Session.OpenSharedItem("C:\test.msg"), Microsoft.Office.Interop.Outlook.MailItem)
            Dim body As String = item.HTMLBody
            ViewData("eBody") = body
    3. And here's the pageLoad script setting the .Text/.Value/.SetValue() of the control:
    <script runat="server">
            Protected Sub pageLoad(sender As Object, e As System.EventArgs)
                eEmail.SetValue(ViewData("eBody"))
            End Sub
    </script>
    OR

    <script runat="server">
            Protected Sub pageLoad(sender As Object, e As System.EventArgs)
                eEmail.Text = ViewData("eBody").ToString
            End Sub
    </script>
    OR

    <script runat="server">
            Protected Sub pageLoad(sender As Object, e As System.EventArgs)
                eEmail.Value = ViewData("eBody").ToString
            End Sub
    </script>
    The output that i get, regardless of how i set the eEmail editor control is the following:
    Click image for larger version. 

Name:	htmlIssue.jpg 
Views:	102 
Size:	56.0 KB 
ID:	24066

    The content i'm trying to set inside of the "Edit Template" htmlEditor control is appearing above the entire panel i have it created in. I can't for the life of me figure out what's causing it or what i can do to get it to display correctly. Can anyone please offer me some insight into this?

    Thanks for your time,

    Mick
    Last edited by Daniil; Aug 21, 2015 at 2:42 PM.
  2. #2
    Hi @navalurzu7,

    Trying to narrow down a problem a bit, could you, please, try this:
    eEmail.Text = "Just a piece of plain text"
    Is that working as expected (i.e. the text is inside the HtmlEditor)?
  3. #3
    I actually solved this in sort of a roundabout way. I created an ext:Store and used a load handler on the store to populate the htmlEditor. I stopped trying to get an outlook .msg file to load, and instead just created some html templates to load into the editor when a dropdown list option was selected.

    Store:
        <ext:Store ID="dsLoadSavedTemplate" runat="server" AutoLoad="false" >
            <Proxy>
                <ext:AjaxProxy Url="/BroadcastEmail/LoadSavedTemplate/">
                    <ActionMethods Read="POST" />
                    <Reader>
                        <ext:JsonReader Root="data" TotalProperty="total" />
                    </Reader>
                </ext:AjaxProxy>
            </Proxy>
            <Model>
                <ext:Model ID="Model3" runat="server" IDProperty="value">
                    <Fields>
                        <ext:ModelField Name="LoadedTemplate" Type="String" />
                    </Fields>
                </ext:Model>
            </Model>
            <Parameters>
                <ext:StoreParameter Name="template" Value="#{cmbSavedTemplates}.value" Mode="Raw" />
            </Parameters>
             <Listeners>
                 <Load Handler="#{eEmail}.setValue(#{dsLoadSavedTemplate}.collect('LoadedTemplate', true)[0]);" />
             </Listeners>
        </ext:Store>
    Code Behind:
    Public Function LoadSavedTemplate(ByVal template As String) As ActionResult
            Dim sUserName As String = HttpContext.User.Identity.Name
            Dim data As New List(Of Object)
            Dim response As FormPanelResult = New FormPanelResult
    
            Try
                template = (From t In DBIEnergyContext.tbl_EmailTemplates Where t.TemplateID = template And t.TemplateOwner = sUserName Select t.TemplateText).First
    
                data.Add(New With {.LoadedTemplate = template})
    
                Dim rds As New StoreResult(data)
                Return rds
    
            Catch ex As System.Exception
                response.Success = False
                response.ExtraParams("msg") = "Error: " & "..." & ex.Message
                Return response
            End Try
    
        End Function
    End Product:
    Click image for larger version. 

Name:	result.jpg 
Views:	94 
Size:	92.1 KB 
ID:	24155
  4. #4
    Okay, thank you for sharing the solution!
  5. #5
    I may need to post this in a separate forum thread, but do you know if its possible at all to take an Outlooks .msg file and display it correctly in an Ext:HtmlEditor control?
  6. #6
    I think we can continue in this thread. I will adjust the thread's title a little bit.

    I cannot answer yes or no, because don't have enough information and, maybe, experience.

    Let's start with... Could you, please, post a content of some sample Outlook.msg file? The entire content, what is needed to be shown in HtmlEditor.
  7. #7
    Ok so say i have an outlook message saved as binary in a sql database. My goal is to grab the binary, convert it back into a message file in code, then put the contents of it into an HTMLEditor control.

    This is what i was trying to do originally, you can see the results of that in my first post. For some reason the content, which i was trying to display INSIDE the htmlEditor, was being displayed outside of the control instead of inside of it.

    I think I can fix this issue by using the Ext:Store, however my big issue now is how to convert the binary that is stored in the database back into a message object.

    As I'm typing this, i'm realizing that I don't really need an answer for this because I am no longer looking to work with Outlook .msg files. Please disregard my request, I'll start a new forum thread if i decide to go this route in the future.

    Thanks for your help!
  8. #8
    Thank you for the explanation. I still don't know what is the content of Outlook msg file, but okay, never mind, if you don't really need a solution on that.

    Thank you for using Ext.NET.

Similar Threads

  1. Replies: 1
    Last Post: Mar 18, 2013, 9:15 AM
  2. Dynamic HTML Content in Accordion Control
    By craig2005 in forum 1.x Help
    Replies: 22
    Last Post: Jan 02, 2011, 10:33 AM
  3. [CLOSED] Submitting Html Content from an HtmlEditor
    By ilanga in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Oct 12, 2010, 11:27 AM
  4. [CLOSED] Script tag HTML rendering on first page load
    By seanwo in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Aug 03, 2010, 8:31 PM
  5. [CLOSED] How to load a page from a Content or Panel using relative path?
    By flormariafr in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Feb 02, 2010, 10:32 AM

Tags for this Thread

Posting Permissions