HighTechTalks DotNet Forums  

problem creating outlookattachments from ServicedComponent

Dotnet Framework (Component Services) microsoft.public.dotnet.framework.component_services


Discuss problem creating outlookattachments from ServicedComponent in the Dotnet Framework (Component Services) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
AT
 
Posts: n/a

Default problem creating outlookattachments from ServicedComponent - 06-21-2004 , 04:39 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
//
}
}
}

Reply With Quote
  #2  
Old   
Florin Lazar [MSFT]
 
Posts: n/a

Default Re: problem creating outlookattachments from ServicedComponent - 07-24-2004 , 04:51 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.


"Peter M" <petermag90 (AT) hotmail (DOT) com> wrote

Quote:
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
//
}
}
}



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.