.NETGURU
problem creating outlookattachments from ServicedComponent
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.component_services.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Peter M
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 to this message...
 
    
Florin Lazar [MSFT] (VIP)
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" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
 
System.Console
System.EnterpriseServices.ActivationOption
System.EnterpriseServices.ServicedComponent
System.Reflection.Missing




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification