C# Outlook doesn't load css in alternate view - c#

As in the topic. I use Outlook as email program, SmtpClient, and MailMessage to send email. I also add AlternateViews, like "text/calendar" (.ics file), and "text/html", which is a html document (I mean it has all tags: <html>,<head>,<body>). The second alternate view (html), does not load css (css I situate in <head><style> my css </style>). The content of <body> is swap dynamically. The MailMessage.Body is null. When I one alternate view (only html, without ics file), css are load. I tried to add css as another alternate view and as attachment. It doesn't work. How to do that?
It works on Outlook Web App, but how to do that in Outlook?

Outlook uses Word for rendering HTML markup. You can read about supported and unsupported HTML elements, attributes, and cascading style sheets properties in the following articles:
Word 2007 HTML and CSS Rendering Capabilities in Outlook 2007 (Part 1 of 2)
Word 2007 HTML and CSS Rendering Capabilities in Outlook 2007 (Part 2 of 2)
Appointment items in Outlook use the RTF markup for bodies, not HTML. See the RTFBody property which returns a Byte array that represents the body of the Microsoft Outlook item in Rich Text Format.
Sub GetRTFBodyForMeeting()
Dim oAppt As Outlook.AppointmentItem
Dim strRTF As String
If Application.ActiveInspector.CurrentItem.Class = olAppointment Then
Set oAppt = Application.ActiveInspector.CurrentItem
strRTF = StrConv(oAppt.RTFBody, vbUnicode)
Debug.Print strRTF
End If
End Sub

Related

SelectPDF missing content after conversion

So I am using SelectPDF to convert an MVC view's html to PDF, but for some reason, a great deal of the content is missing from the PDF.
I have tested the program on other sites I have made in MVC and they work...
So as per the readme doc's recommendation, I use this code to produce a
SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();
SelectPdf.PdfDocument doc = converter.ConvertUrl(HTMLPath);
//SelectPdf.PdfDocument doc = converter.ConvertHtmlString(ViewHTML);
doc.Save(PDFSavePath);
doc.Close();
So HTMLSave path is the location of the HTML file created from the rendered MVC view. While ViewHTML contains the HTML in the form of a string.
So this is how the HTML looks (the file and the view look identical, I did double check in case the HTML was captured incorrectly):
But this is how the PDF looks:
Absolutely tragic...
Not sure if it will be helpful, but here's the HTML:
https://drive.google.com/open?id=0B8DiACLG11oYd3p5Tzc2ZlJQLVk
Unfortunately, all the HTML is on one line thanks to the MVC View to HTML
It seems that the html/css engine used to render the page does not support vh, vw for font sizes. It's a common issue with all converters, so probably you should try to change this if you need the page converted to pdf.
Later update: it seems that there is support for vw, but not for vh. That's why the "each" words appear. They use vw in css.

Html Image size when added via Microsoft.Office.Interop.Outlook

Using MS outlook 2010, c# in Visual Studio 2012, Microsoft.Office.Interop.Outlook version 14.
I'm trying to use outlook automation to open a new email, pre-populated with some html.
Here's the code:
using Microsoft.Office.Interop.Outlook;
using Outlook = Microsoft.Office.Interop.Outlook;
...
// bring up outlook
Application oApp = new Application();
Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMailItem.To = "any#any.com";
string body = System.IO.File.ReadAllText("welcome.html");
oMailItem.HTMLBody = body;
oMailItem.Subject = "Welcome";
oMailItem.Display(false);
Where welcome.html looks like this:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Welcome</title>
</head>
<body lang="EN-AU">
<p>hello world</p> <!-- XXX : repeat as necessary -->
<p>
<img src="http://www.w3.org/2008/site/images/logo-w3c-mobile-lg" alt="logo" />
</p>
</body>
</html>
Note: any logo (which is not too small) can be used - the one I have used is just an example.
The code works ok, but there is a problem with the logo size.
The problem can occur when the html line marked at XXX is repeated many times, (say 50).
There are two cases:
a) in outlook, before you send the email, scroll down to view the complete document. I noticed that outlook seems to resize the image. When the email is sent, the receiver sees the image in normal size:
b) in outlook, before you send the email, DO NOT scroll down to view the complete document. When the email is received, the image is small. (32 pixels by 32 pixels):
The email resulting from case a) is the desired outcome. But it would be better if the user didn't have to scroll down to preview the whole thing before sending.
Any workarounds ? Using html width and height attributes on img to explicitly set the dimensions seems to work, but this is not desirable because in real life, the image is dynamically selected (so that the size can't be hardcoded). If there was some way (via automation) to simulate previewing the whole email before sending, this might work as well.
Moe,
Outlook uses Word as an email editor. You can read about supported and unsupported HTML elements, attributes, and cascading style sheets properties in the following series of articles in MSDN:
Word 2007 HTML and CSS Rendering Capabilities in Outlook 2007 (Part 1 of 2)
Word 2007 HTML and CSS Rendering Capabilities in Outlook 2007 (Part 2 of 2)

How to write rich text to word document generated from htm file in C#

I am trying to generate a word doc from saved HTML file using an Open XML library.
If the HTML file does not contain an image I can simply use the code below and write text content to word doc.
HtmlDocument doc = new HtmlDocument();
doc.Load(fileName); //fileName is the Htm file
string Detail = string.Empty;
string webData = string.Empty;
HtmlNode hcollection = doc.DocumentNode.SelectSingleNode("//body");
Detail = hcollection.InnerText;
But if the HTML file contains an embedded image I am struggling to include that image in the word doc.
Using hcollection.InnerText only writes the text part and excludes the image.
When I use
HtmlNode hcollection = doc.DocumentNode.SelectSingleNode("//body");
Detail = hcollection.InnerHtml;
All the HTML tags get written to the word doc along with path of Image in the tag
<table border='0' width='100%' cellpadding='0' cellspacing='0' align='center'>
<tr><td valign='top' align="left">
<div style='width:100%'><div id="div_img">
<div>
<img src="http://www.myweb.com/web/img/2013/07/18/img_1.jpg">
<span>Sample Text</span></div></div><br><br>Sample Text Content here<br><br> </div></td></tr></table>
How to remove the html tags and instead of path shown like
<img src="http://www.myweb.com/web/img/2013/07/18/img_1.jpg">
the corresponding picture gets loaded.
Please help.
You'll need to look at the HTML and translate it to OpenXML somehow.
I've used HtmlToOpenXml open-source library (license), and that works well enough. It should handle images (inline, local or remote) and correctly insert them into the OpenXML document. I recently submitted a patch which was accepted, so the project is still somewhat active.
There are some limitations with the library though:
Javascript (<script>), CSS <style>, <meta> and other not supported tags does not generate an error but are ignored.
It does handle inline style information, but it entirely ignores other CSS, which was something I needed. I ended up integrating some simple parsing of a single <style> element from another open-source project (jsonfx, using MIT license).
Note: handling multiple <style> elements, downloading CSS files, sorting out which style rules have precedence -- these are all problems which I did not address.
Actually the converting of HTML document to MS Word is a very complex task and there are a lot of cases besides of IMAGE tags which need to be solved. The difference between Open XML and HTML formats is absolutely decisive.
If I were you I would look for 3rd party tools for that. It would be chiper to pay for them than spending weeks on investigation and learning of all aspects of the task, writing the code, and then fixing miltiple bugs.
Personaly me used Aspose.Words library for that. It worked perfectly fine, but maybe you want to try another one.

How to search the text in WebBrowser Control

Hai, we have a requirement like previewing the documents as like in
windows7/vista "preview Pane" and have to implement the search
functionality in Winforms.For that, I have loaded the Ms office
docuemnts, and Excel Sheets and Power Point documents into Webbrowser
Control in html format.Now we need to implement the search
functionality in that webbrowser Control. For that we have
implemented the search functionality using the following code
public bool FindNext(string text, WebBrowser webBrowser1)
{
IHTMLDocument2 doc = webBrowser1.Document.DomDocument as IHTMLDocument2;
IHTMLSelectionObject sel =doc.selection;// (IHTMLSelectionObject)doc.selection;
IHTMLTxtRange rng = sel.createRange() as IHTMLTxtRange;
rng.collapse(false); // collapse the current selection so we start from the end of the previous range
if (rng.findText(text, 1000000, 0))
{
rng.select();
return true;
}
else
FindFirst(text, webBrowser1);
return false;
}
This code is working fine for searching the string values in word
Document for all the occurences. But when it Comes to Excel and PPt
documents this code doesn't work properly.it finds only the first
occurrence of the string other occurrences doesn't find. while
debugging i found that,for word Documents "IHTMLDocument2" object
stores the html Content in "innerHTML" and "innerText" with some
values. But for Excel it stores the text in "innerHTML" only by using
the Frames, and sheets are referenced to local temporary .html files
and it didn't have any "innerText" content it showing as null.
Please provide the solution to search the text in webbrowser control which loaded the html content, that is converted from
Excel,PPT to html type and displaying in webbrowser control.
If you have any queries please feel to ask me.
Thank You.

Extracting XML from XMLFormView

Is there a way to get the XML presented in a XMLFormView? I'm trying to create a custom web part with a "Save as PDF" button for an InfoPath form. The idea is to combine the XML with the form's XSL and make the resulting HTML into PDF which is presented to the user as a popup.
Because it is to be presented as a popup, using Workflows is not an option.
http://msdn.microsoft.com/en-us/library/microsoft.office.infopath.server.controls.xmlformview.xmllocation.aspx
This property will give you the Url of the Base XML file. You can read the Stream reader to read this XML.
Take a look at my codeplex project http://ip2html.codeplex.com/
It allows you to generate HTML from the given (InfoPath) XML & (XMLFormView) XSLT.
We ended up using the XmlFormHostItem.NotifyHost method to send HTML to a custom web part in a button-clicked event, which converted the HTML to PDF using Winnovative HTML to PDF converter.
HTML generation from InfoPath code-behind:
var formData = new XmlDocument();
var xslt = new XslCompiledTransform(true);
// Load the form data
formData.LoadXml(MainDataSource.CreateNavigator().InnerXml);
// Extract the stylesheet from the package
xslt.Load(ExtractFromPackage("Print.xsl")); // (uses Template.OpenFileFromPackage(string fileName) to get xsl)
// Perform XSL-transformation
// [...]
// Send HTML to web part
this.NotifyHost(formData.InnerXml);
One drawback of this method is that the NotifyHost event only fires once per form, so if the user clicks 'Save as PDF' and then cancels, he must reload the form in order to be able to save as PDF.

Categories