Solved

VB.NET/Outlook Message Display Issue

Posted on 2008-10-13
10
570 Views
Last Modified: 2012-05-05
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.
0
Comment
Question by:tnesupport
  • 5
  • 5
10 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 22709461
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
 
LVL 1

Author Comment

by:tnesupport
ID: 22712396
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 22712440
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
 
LVL 1

Author Comment

by:tnesupport
ID: 22712509
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
 
LVL 1

Author Comment

by:tnesupport
ID: 22712529
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 22712535
Did you try other encodings such as UTF?
0
 
LVL 1

Author Comment

by:tnesupport
ID: 22712571
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
 
LVL 1

Author Closing Comment

by:tnesupport
ID: 31505607
Thanks a lot man!
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 22712602
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 22712620
Happy that the problem is sorted.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now