Justin Barnes

First question: If I use the outlook object model included with VS2005, is it only going to work with clients that have office 2003 installed I'm using my code to create an appointment via a web app, and can't rely on any specific version installed.

I found another way to create the file, so that isn't too much of an issue if so. But my second quesiton is:

I'd like to create a link in the body, but when I add HTML, it just renders it all as text. Is there a property that i'm missing

Here is the code that i'm currently using:

Private Sub AddOutlookReminder()

Dim icalendar As String = BuildApptItem()

Response.ContentType = "html/x-vCalendar"

Response.AppendHeader("content-disposition", "inline; filename=game.vcs")

Response.Write(icalendar)

Response.End()

End Sub

Private Function BuildApptItem() As String

' Obviously, these values would come from the UI somewhere...

Return BuildVCalendar(#1/17/2007 2:00:00 PM#, _

#1/17/2007 3:00:00 PM#, "2:00 PM at <a href='dingbats.com'>Dingbats</a> concert", _

"Concert", 3)

End Function

Private Function BuildVCalendar(ByVal startDate As DateTime, _

ByVal endDate As DateTime, ByVal description As String, _

ByVal summary As String, ByVal priority As Integer) As String

Dim sw As New System.IO.StringWriter

sw.WriteLine("BEGIN: VCALENDAR")

sw.WriteLine("VERSION:1.0")

sw.WriteLine("BEGIN: VEVENT")

sw.WriteLine("DTSTART:{0:yyyyMMdd\THHmmss\Z}", _

startDate.ToUniversalTime)

sw.WriteLine("DTEND:{0:yyyyMMdd\THHmmss\Z}", _

endDate.ToUniversalTime)

sw.WriteLine("DESCRIPTION;ENCODING=HTML:{0}", _

description)

sw.WriteLine("SUMMARY;ENCODING=QUOTED-PRINTABLE:{0}", summary)

sw.WriteLine("PRIORITY:{0}", priority)

sw.WriteLine("END:VEVENT")

sw.WriteLine("END:VCALENDAR")

Return sw.ToString()

End Function



Re: Visual Studio Tools for Office HTML in Outlook meeting body

Sue Mosher - Outlook MVP

Since Outlook AppointmentItem bodies are rich-text, not HTML, they can't use any HTML tagging. Just include your link in the summary.

Why would the Outlook version matter if you're building the appointment with vCalendar (which is the right way to do it from a web app)





Re: Visual Studio Tools for Office HTML in Outlook meeting body

Justin Barnes

Sue,

Is there a way to make the link have a display different from the location like in HTML I've never done work in richtext before.

As for why outlook verison would matter, I was just wondering if the .net objects might be more powerful or easier to use. I'll stick with the vCalender for now.





Re: Visual Studio Tools for Office HTML in Outlook meeting body

Sue Mosher - Outlook MVP

Justin Barnes wrote:

Is there a way to make the link have a display different from the location like in HTML

Not in an appointment that Outlook receives as vCal/iCal. With desktop Outlook objects, only in Outlook 2007.





Re: Visual Studio Tools for Office HTML in Outlook meeting body

Peter D. Jorgensen

Hi Sue,
I'm having almost the same problem.

I need to insert a link to a url that is of a custom type. When installing Microsoft Dynamics NAV it creates a new url-type starting with "navision//" which works fine in the desktop/IE.

First I tried using automation, but HTMLBody is not available in OL2003.
Secondly I tried using a cvs, but the rtf editor apparently doesn't recognize the customer url type.

Anyway to get the url underlined in an automatically generated appointment

/Peter




Re: Visual Studio Tools for Office HTML in Outlook meeting body

Sue Mosher - Outlook MVP

Peter, same answer as for Justin -- not in Outlook 2003. In Outlook 2007, it can be done with WordEditor, which is available for appointment items.



Re: Visual Studio Tools for Office HTML in Outlook meeting body

Al Loup

Hi Sue: I read through this thread but don't understand your comment about RichText and WordEditor. I want to apply formatting programmatically using VBA. Below is a snipit of what I tried. Everything worked except the html in ".Body = ..." How can I apply some formatting programmatically to the body of the appointment item


Dim oOutlookApp As Outlook.Application
Dim myAppointmentItem As Outlook.AppointmentItem
Set oOutlookApp = Outlook.Application
Set myAppointmentItem = oOutlookApp.CreateItem(olAppointmentItem)
With myAppointmentItem
.MeetingStatus = olMeeting
.Subject = "DO NOT REPLY: this is a test"
.Location = "Conf Nr: nnn-nnn-nnnn"
.Start = #4/24/2007 1:30:00 PM#
.Duration = 90
.Body = "This is a <b> test </b>"
End With

thanks, Al





Re: Visual Studio Tools for Office HTML in Outlook meeting body

Sue Mosher - Outlook MVP

Al, in Outlook 2007, you would use AppointmentItem.GetInspector.WordEditor to return a Word.Document object and use Word properties and methods to write the body of the appointment, including the hyperlink. (This is where the Word macro recorder can come in handy.)

For earlier versions, Redemption's SafeInspector object might be your best approach.





Re: Visual Studio Tools for Office HTML in Outlook meeting body

Al Loup

Hi Sue: thanks for the reply. I'm using Office 2007. I tried using the Word document object, but got errors. Could you look at the code below and tell me what I'm doing wrong I've put the errors in comments. thanks, Al

Dim oOutlookApp As Outlook.Application
Set oOutlookApp = Outlook.Application
Dim myAppointmentItem As Outlook.AppointmentItem
Set myAppointmentItem = oOutlookApp.CreateItem(olAppointmentItem)
Dim myInspector As Inspector
Set myInspector = myAppointmentItem.GetInspector
Dim doci As Outlook.DocumentItem
Dim nsp As Outlook.NameSpace
Dim mpfInbox As Outlook.Folder
Set nsp = oOutlookApp.GetNamespace("MAPI")
Set mpfInbox = nsp.GetDefaultFolder(olFolderInbox)


Set doci = mpfInbox.Items.Add(olWordDocumentItem) 'ERROR: Cannot create Outlook document items.

Set doci = myInspector.WordEditor 'ERROR: type mismatch





Re: Visual Studio Tools for Office HTML in Outlook meeting body

Sue Mosher - Outlook MVP

Al, you seem to be confusing the DocumentItem object in the Outlook object model with the Word.Document object returned by Inspector.WordEditor. Looks like you're using VBA/VB6, not VB.NET, so what you want is something like this:

Code Snippet

Dim objDoc as Word.Document

Dim objSel as Word.Selection

Set objDoc = myInspector.WordEditor

Set objSel = objDoc.Windows(1).Selection

Once you have the Word.Selection object, you can move the insertion point, insert text, etc. to do almost anything you want in the body of the AppointmentItem. This is where the Word macro recorder can really help out, since the code it generates usually relies heavily on a Selection object.

<shameless plug>I have a whole chapter on working with item bodies in my new Outlook 2007 programming book, which will be out next month.</shameless plug>

One more note on this topic: I have no idea what will happen if you try to send a meeting request with a formatted body as an iCalendar item. The formatting should "stick," though, if you're sending internally to other Exchange users.