Groups | Blog | Home
all groups > dotnet component services > june 2004 >

dotnet component services : problem creating outlookattachments from ServicedComponent


petermag90 NO[at]SPAM hotmail.com
6/21/2004 1:39:33 PM
I am trying to interop with Outlook from a serviced component See
attached code below.
I am running my component inside a hostprocess (dllhost).
I succeds in creating the application object and the MailItem object,
but fails when I try to add an attachment. When I run the same code as
a standalone exe everything works just fine.

My target os is Win2k server

Please help me..

Component Code:

using System;
using System.EnterpriseServices;
using Interop.Outlook;
using System.Reflection;

[assembly: ApplicationName("OutlookTest")]
[assembly: ApplicationActivation(ActivationOption.Server)]
[assembly: ApplicationAccessControl(false)]


namespace OutlookTestComponent
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class OutlookTestComponent : ServicedComponent
{
public OutlookTestComponent()
{
//
// TODO: Add constructor logic here
//
}

public string test()
{
Interop.Outlook._Application OutlookApp = new
Interop.Outlook.ApplicationClass();

MailItem m = OutlookApp.CreateItem(OlItemType.olMailItem) as
MailItem;


object optional = System.Reflection.Missing.Value;
m.Attachments.Add(@"c:\temp\test.txt", optional, optional,
optional);

return "Success";
}
}
}


Client Code

using System;
using OutlookTestComponent;

namespace oltest
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
OutlookTestComponent.OutlookTestComponent c = new
OutlookTestComponent.OutlookTestComponent();

Console.WriteLine(c.test());
//
// TODO: Add code to start application here
//
}
}
Florin Lazar [MSFT]
7/24/2004 1:51:44 PM
Hi Peter,

What error do you get when it fails?

Regards,
--
Florin Lazar - Microsoft - [ http://blogs.msdn.com/florinlazar ]
Please do not send email directly to this alias. This alias is for newsgroup
purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.


[quoted text, click to view]

AddThis Social Bookmark Button