PDA

View Full Version : Displaying Outlook.msg in an HTMLEditor control on page load



navalurzu7
Jul 08, 2015, 7:08 PM
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:
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

Daniil
Aug 21, 2015, 10:44 AM
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)?

navalurzu7
Aug 21, 2015, 1:20 PM
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:
24155

Daniil
Aug 21, 2015, 1:38 PM
Okay, thank you for sharing the solution!

navalurzu7
Aug 21, 2015, 1:42 PM
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?

Daniil
Aug 21, 2015, 2:41 PM
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.

navalurzu7
Aug 21, 2015, 3:41 PM
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!

Daniil
Aug 21, 2015, 4:07 PM
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.