VB.NET/Outlook Message Display Issue

Hello everyone.

I was working on a very complex macro in VBA using Outlook 2007's macro editor, but then realized the project was more suited for a standalone executable. Feeling working on this in VBA was too outdated, I switched over to VB.NET (on VS Express 2008), and began porting my code.

Everything seems to be working fine as 90% of the code is simple logic, not playing around with Outlook. The one problem I am having is involving code that reads HTML from a file & places it in the HTMLBody of a new Outlook message.

When using VBA code with what appears to be the exact same functionality (see below), I get different results. When I scan the HTML file's text & put it in the messages HTML body using VBA everything ends up fine (images intact, no weird formatting errors).

When I scan the same HTML file using VB.NET code & fill in the HTML body, I get strange formatting errors that are black diamond shaped boxes with question marks inside.  Up until today I was also getting errors stating ""The image cannot be displayed. Your computer may not have enough memory to open the image, or the image may have been corrupted. Restart your computer, then open the file again. If the red x still appears, you may have to delete the image and then insert it again."  Here's a screenshot of what I'm talking about... http://www.tneus.com/images/screenshot.jpg

Yet when I test the same thing again in VBA (after receiving this error), everything once again still works fine.

The HTML template I am using was exported from an OFT file in Outlook, so there is some strange markup that's not in regular HTML files. I don't know why or how this would affect the display of information though, if everything is working fine with one method.

I've asked this question on several forums (and waited about a week for responses) and have had zero help.  Any help would be GREATLY appreciated, as this is immensely frustrating.

Thank you.
LVL 1
tnesupportAsked:
Who is Participating?
 
CodeCruiserConnect With a Mentor Commented:
Did you try other encodings such as UTF?
0
 
CodeCruiserCommented:
Regarding the diamonds with questions marks, if you notice that the line "Don't Miss Out" has that diamond with question mark in place of ', you would easily understand the source of the problem. In VB.NET, ' is used to comment the code. So anything beyond ' is considered a commend. Try Replacing those characters with chr() function by using appropriate numeric value such as 13 is for vbcrlf.
The formatting may be going wrong because of this basic issue. I think if you solve this problem then other problems would be solved automatically. If not, do come back.
0
 
tnesupportAuthor Commented:
This may be part of the problem, but your suggestion pointed me in the right direction.  Some diamonds are being caused by whitespace..for example..

<p><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:
      "Verdana","sans-serif";mso-bidi-font-family:Arial;color:#666666;
      mso-bidi-font-weight:bold'>Call us today to register for this exciting
      preview event. We look forward to seeing you there!<span
      style='mso-spacerun:yes'>  </span><o:p></o:p></span></p>

The whitespace in between <span style='mso-spacerun:yes'>  </span> those two tags is causing this to appear.

This seems like an encoding issue to me but i have 0 experience with this subject...do you have any ideas?
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
CodeCruiserCommented:
I would suggest you to first replace the single quotes as the span has many of these in pairs for styles. If that does not help then look for other problems. The reason is that i send HTML based emails from VB.NET and never had a problem.

Also, never saw this tag before
<o:p></o:p>
0
 
tnesupportAuthor Commented:
I understand..here's some more info...When I change my streamreader's encoding to ANSI, there is no longer any black diamonds but all the images will not show ("The image cannot be displayed. Your computer may not have enough memory to open the image, or the image may have been corrupted. Restart your computer, then open the file again. If the red x still appears, you may have to delete the image and then insert it again." )

The tag <o:p></o:p> is something with Microsoft Office..as the HTML file was exported from OFT file.
0
 
tnesupportAuthor Commented:
Excuse me, when I re-save the file in notepad using UTF8 encoding, and set my stream reader to UTF8 encoding it works...does anyone by any chance know the default encoding when you save a HTML file from outlook?  Does it use the system's default encoding?  Or does anyone know the default encoding of the Scripting.FileSystemObject..?
0
 
tnesupportAuthor Commented:
This was the solution..the encoding for stream reader needed to be set to Encoding.Default...thanks a lot for helping me see what the problem was here CodeCruiser :).
0
 
tnesupportAuthor Commented:
Thanks a lot man!
0
 
CodeCruiserCommented:
The encoding can be changed for outgoing messages through Tools->Options Mail Format tab, and International Options button. I think when saving messages as HTML, the source encoding is used.
0
 
CodeCruiserCommented:
Happy that the problem is sorted.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.