473,385 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Open Outlook on user machine

How can I launch Outlook on users machines when they click a button on a web
form (InfoPath)?

Thanks
Jul 3 '08 #1
23 5919
You can't.

Only client-side code can ask the client to do something. Now, you can
certainly have client code that "asks" the browser to open its default mail
client, and that *might* be Outlook, but again, it might not be.

And, for security reasons, JavaScript (the client code we're talking about)
has no abilities when it comes to the OS.

"andyoye" <an*****@nospam.comwrote in message
news:u7**************@TK2MSFTNGP03.phx.gbl...
How can I launch Outlook on users machines when they click a button on a
web form (InfoPath)?

Thanks

Jul 3 '08 #2
I found following from
http://forums.devx.com/showthread.ph...hlight=outlook

looks like I am missing some namespace/referneces as "Outlook.Application"
could not be found.
Outlook.Application objOutlk = new Outlook.Application();
//Outlook
const int olMailItem = 0;
object objMail = new object();
objMail = objOutlk.CreateItem(olMailItem);
//Email item
objMail.To = emaila.Text;
objMail.cc = "";
//Enter an address here To include a carbon copy; bcc is For blind carbon
copy's
//Set up Subject Line
objMail.subject = "Quality Assurance Letter";
//To add an attachment, use:
//objMail.attachments.add("C:\MyAttachmentFile.txt")
string msg;
msg = "body test msg";
objMail.body = msg;
//Use this To display before sending, otherwise call objMail.Send to send
without reviewing
objMail.display();
//Use this To display before sending, otherwise call objMail.Send to send
without reviewing
//Clean up
objMail = null;
"Scott M." <s-***@nospam.nospamwrote in message
news:Op*************@TK2MSFTNGP04.phx.gbl...
You can't.

Only client-side code can ask the client to do something. Now, you can
certainly have client code that "asks" the browser to open its default
mail client, and that *might* be Outlook, but again, it might not be.

And, for security reasons, JavaScript (the client code we're talking
about) has no abilities when it comes to the OS.

"andyoye" <an*****@nospam.comwrote in message
news:u7**************@TK2MSFTNGP03.phx.gbl...
>How can I launch Outlook on users machines when they click a button on a
web form (InfoPath)?

Thanks


Jul 3 '08 #3
On Jul 3, 5:59 pm, "andyoye" <andy...@nospam.comwrote:
How can I launch Outlook on users machines when they click a button on a web
form (InfoPath)?

Thanks
I do not know why do you want to open outlook, however from
application programming side, the normal requirement is to mail
something to someone... In which case System.Web.Mail will help.

- Cnu
Jul 3 '08 #4
Add, from Office (Setup/Add/Repair) ".Net Programmability Support" (not as
load on request, but unconditionally).

Add the reference to Office Interop to your project and the line

using Outlook=Microsoft.Office.Interop.Outlook;

(note that this alias may help to remove ambiguity about Application and
Outlook.Application)

and, to clean up, the code is missing a lot. Try adding:

objOutlk.Quit();
objOutlk= null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
More details in"Microsoft .Net Development For Microsoft Office", Andrew
Whitechapel, Microsoft Press.
Vanderghast, Access MVP

"andyoye" <an*****@nospam.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>I found following from
http://forums.devx.com/showthread.ph...hlight=outlook

looks like I am missing some namespace/referneces as "Outlook.Application"
could not be found.
Outlook.Application objOutlk = new Outlook.Application();
//Outlook
const int olMailItem = 0;
object objMail = new object();
objMail = objOutlk.CreateItem(olMailItem);
//Email item
objMail.To = emaila.Text;
objMail.cc = "";
//Enter an address here To include a carbon copy; bcc is For blind carbon
copy's
//Set up Subject Line
objMail.subject = "Quality Assurance Letter";
//To add an attachment, use:
//objMail.attachments.add("C:\MyAttachmentFile.txt")
string msg;
msg = "body test msg";
objMail.body = msg;
//Use this To display before sending, otherwise call objMail.Send to send
without reviewing
objMail.display();
//Use this To display before sending, otherwise call objMail.Send to send
without reviewing
//Clean up
objMail = null;
"Scott M." <s-***@nospam.nospamwrote in message
news:Op*************@TK2MSFTNGP04.phx.gbl...
>You can't.

Only client-side code can ask the client to do something. Now, you can
certainly have client code that "asks" the browser to open its default
mail client, and that *might* be Outlook, but again, it might not be.

And, for security reasons, JavaScript (the client code we're talking
about) has no abilities when it comes to the OS.

"andyoye" <an*****@nospam.comwrote in message
news:u7**************@TK2MSFTNGP03.phx.gbl...
>>How can I launch Outlook on users machines when they click a button on a
web form (InfoPath)?

Thanks


Jul 3 '08 #5
I do want to open outlook, thats the MAIN objective here.

I ran below code:

Outlook.Application outlookApp = new Outlook.Application();

Outlook.MailItem message =

(Outlook.MailItem)outlookApp.CreateItem(Outlook.Ol ItemType.olMailItem);

message.Subject = "Hello World";

message.Recipients.Add(A@aol.com);

message.Body = "Hello. This is a test.";

I get below error when i try to run it.

System.Security.SecurityException
That assembly does not allow partially trusted callers.
at
System.Security.CodeAccessSecurityEngine.ThrowSecu rityException(Assembly
asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh,
SecurityAction action, Object demand, IPermission permThatFailed)


"Duggi" <Du***************@gmail.comwrote in message
news:89**********************************@u12g2000 prd.googlegroups.com...
On Jul 3, 5:59 pm, "andyoye" <andy...@nospam.comwrote:
>How can I launch Outlook on users machines when they click a button on a
web
form (InfoPath)?

Thanks

I do not know why do you want to open outlook, however from
application programming side, the normal requirement is to mail
something to someone... In which case System.Web.Mail will help.

- Cnu

Jul 3 '08 #6
You're missing the point. The code you show below will only work if it is
*running* on a machine with Outlook installed. Since you said "web form",
then this could will be running on a web server and there are two issues
with that:

1. Most web servers don't have Outlook installed on them, nor would you want
to as it poses a security risk.
2. Even if the server had Outlook (or the Outlook Primary InterOp Assembly -
PIA), this code runs on the server and won't do anything for the client.

-Scott

"andyoye" <an*****@nospam.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>I found following from
http://forums.devx.com/showthread.ph...hlight=outlook

looks like I am missing some namespace/referneces as "Outlook.Application"
could not be found.
Outlook.Application objOutlk = new Outlook.Application();
//Outlook
const int olMailItem = 0;
object objMail = new object();
objMail = objOutlk.CreateItem(olMailItem);
//Email item
objMail.To = emaila.Text;
objMail.cc = "";
//Enter an address here To include a carbon copy; bcc is For blind carbon
copy's
//Set up Subject Line
objMail.subject = "Quality Assurance Letter";
//To add an attachment, use:
//objMail.attachments.add("C:\MyAttachmentFile.txt")
string msg;
msg = "body test msg";
objMail.body = msg;
//Use this To display before sending, otherwise call objMail.Send to send
without reviewing
objMail.display();
//Use this To display before sending, otherwise call objMail.Send to send
without reviewing
//Clean up
objMail = null;
"Scott M." <s-***@nospam.nospamwrote in message
news:Op*************@TK2MSFTNGP04.phx.gbl...
>You can't.

Only client-side code can ask the client to do something. Now, you can
certainly have client code that "asks" the browser to open its default
mail client, and that *might* be Outlook, but again, it might not be.

And, for security reasons, JavaScript (the client code we're talking
about) has no abilities when it comes to the OS.

"andyoye" <an*****@nospam.comwrote in message
news:u7**************@TK2MSFTNGP03.phx.gbl...
>>How can I launch Outlook on users machines when they click a button on a
web form (InfoPath)?

Thanks



Jul 3 '08 #7
Yes it is a web form, but can the code launch Outlook on a user machine?
"Scott M." <s-***@nospam.nospamwrote in message
news:%2******************@TK2MSFTNGP05.phx.gbl...
You're missing the point. The code you show below will only work if it is
*running* on a machine with Outlook installed. Since you said "web form",
then this could will be running on a web server and there are two issues
with that:

1. Most web servers don't have Outlook installed on them, nor would you
want to as it poses a security risk.
2. Even if the server had Outlook (or the Outlook Primary InterOp
Assembly - PIA), this code runs on the server and won't do anything for
the client.

-Scott

"andyoye" <an*****@nospam.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>>I found following from
http://forums.devx.com/showthread.ph...hlight=outlook

looks like I am missing some namespace/referneces as
"Outlook.Application" could not be found.
Outlook.Application objOutlk = new Outlook.Application();
//Outlook
const int olMailItem = 0;
object objMail = new object();
objMail = objOutlk.CreateItem(olMailItem);
//Email item
objMail.To = emaila.Text;
objMail.cc = "";
//Enter an address here To include a carbon copy; bcc is For blind carbon
copy's
//Set up Subject Line
objMail.subject = "Quality Assurance Letter";
//To add an attachment, use:
//objMail.attachments.add("C:\MyAttachmentFile.txt")
string msg;
msg = "body test msg";
objMail.body = msg;
//Use this To display before sending, otherwise call objMail.Send to send
without reviewing
objMail.display();
//Use this To display before sending, otherwise call objMail.Send to send
without reviewing
//Clean up
objMail = null;
"Scott M." <s-***@nospam.nospamwrote in message
news:Op*************@TK2MSFTNGP04.phx.gbl...
>>You can't.

Only client-side code can ask the client to do something. Now, you can
certainly have client code that "asks" the browser to open its default
mail client, and that *might* be Outlook, but again, it might not be.

And, for security reasons, JavaScript (the client code we're talking
about) has no abilities when it comes to the OS.

"andyoye" <an*****@nospam.comwrote in message
news:u7**************@TK2MSFTNGP03.phx.gbl...
How can I launch Outlook on users machines when they click a button on
a web form (InfoPath)?

Thanks



Jul 3 '08 #8
Michael,

There are a couple of things wrong with this:

1. The OP asked about opening Outlook on the client but from Web Form code,
which can't be done.
2. Your clean up code is not correct.
a. When calling a COM object via COM InterOp, you must call the
Marshall class's ReleaseComObject method, which tells the CLR to release it
connection to the underlying COM object. Since COM objects are freed from
memory when their reference count goes to zero, this step is critical
otherwise the object will persist in memory even though the .NET program
that called it no longer has any reference to it.
b. You really should not ever need to call GC anything except for under
very special circumstances. The GC runs in a separate thread from your .NET
application and the moment you call GC from your application, you force it
to operate in the same thread as your main application. This can actually
result in your application's performance degrading. The bottom line is that
the GC works quite well all on its own and you really shouldn't interfere
with its normal operations because you will most likely not improve matters.

The correct way to "clean up" a COM object from .NET is this:

objOutlook.Quit();
System.Marshall.ReleaseComObjct(objOutlook);
objOutlook = null;

-Scott

"Michel Walsh" <va*************************@nospam.comwrote in message
news:6D**********************************@microsof t.com...
Add, from Office (Setup/Add/Repair) ".Net Programmability Support" (not as
load on request, but unconditionally).

Add the reference to Office Interop to your project and the line

using Outlook=Microsoft.Office.Interop.Outlook;

(note that this alias may help to remove ambiguity about Application and
Outlook.Application)

and, to clean up, the code is missing a lot. Try adding:

objOutlk.Quit();
objOutlk= null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
More details in"Microsoft .Net Development For Microsoft Office", Andrew
Whitechapel, Microsoft Press.
Vanderghast, Access MVP

"andyoye" <an*****@nospam.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>>I found following from
http://forums.devx.com/showthread.ph...hlight=outlook

looks like I am missing some namespace/referneces as
"Outlook.Application" could not be found.
Outlook.Application objOutlk = new Outlook.Application();
//Outlook
const int olMailItem = 0;
object objMail = new object();
objMail = objOutlk.CreateItem(olMailItem);
//Email item
objMail.To = emaila.Text;
objMail.cc = "";
//Enter an address here To include a carbon copy; bcc is For blind carbon
copy's
//Set up Subject Line
objMail.subject = "Quality Assurance Letter";
//To add an attachment, use:
//objMail.attachments.add("C:\MyAttachmentFile.txt")
string msg;
msg = "body test msg";
objMail.body = msg;
//Use this To display before sending, otherwise call objMail.Send to send
without reviewing
objMail.display();
//Use this To display before sending, otherwise call objMail.Send to send
without reviewing
//Clean up
objMail = null;
"Scott M." <s-***@nospam.nospamwrote in message
news:Op*************@TK2MSFTNGP04.phx.gbl...
>>You can't.

Only client-side code can ask the client to do something. Now, you can
certainly have client code that "asks" the browser to open its default
mail client, and that *might* be Outlook, but again, it might not be.

And, for security reasons, JavaScript (the client code we're talking
about) has no abilities when it comes to the OS.

"andyoye" <an*****@nospam.comwrote in message
news:u7**************@TK2MSFTNGP03.phx.gbl...
How can I launch Outlook on users machines when they click a button on
a web form (InfoPath)?

Thanks


Jul 3 '08 #9
No.

Read the whole thread though. I've got to believe that understanding
"mailto:..." is what you need.

The person who posted the code wrote: "this should spawn on the client
machine not the web server. but then again im using an all in one so ....".

This means they were testing from the server itself. The code works fine
in a windows application. The permission errors you refered to in another
email likely are that the ASP.Net account doesn't have permission to run
outlook. Don't give it permision though...

"andyoye" wrote:
Yes it is a web form, but can the code launch Outlook on a user machine?
"Scott M." <s-***@nospam.nospamwrote in message
news:%2******************@TK2MSFTNGP05.phx.gbl...
You're missing the point. The code you show below will only work if it is
*running* on a machine with Outlook installed. Since you said "web form",
then this could will be running on a web server and there are two issues
with that:

1. Most web servers don't have Outlook installed on them, nor would you
want to as it poses a security risk.
2. Even if the server had Outlook (or the Outlook Primary InterOp
Assembly - PIA), this code runs on the server and won't do anything for
the client.

-Scott

"andyoye" <an*****@nospam.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>I found following from
http://forums.devx.com/showthread.ph...hlight=outlook

looks like I am missing some namespace/referneces as
"Outlook.Application" could not be found.
Outlook.Application objOutlk = new Outlook.Application();
//Outlook
const int olMailItem = 0;
object objMail = new object();
objMail = objOutlk.CreateItem(olMailItem);
//Email item
objMail.To = emaila.Text;
objMail.cc = "";
//Enter an address here To include a carbon copy; bcc is For blind carbon
copy's
//Set up Subject Line
objMail.subject = "Quality Assurance Letter";
//To add an attachment, use:
//objMail.attachments.add("C:\MyAttachmentFile.txt")
string msg;
msg = "body test msg";
objMail.body = msg;
//Use this To display before sending, otherwise call objMail.Send to send
without reviewing
objMail.display();
//Use this To display before sending, otherwise call objMail.Send to send
without reviewing
//Clean up
objMail = null;
"Scott M." <s-***@nospam.nospamwrote in message
news:Op*************@TK2MSFTNGP04.phx.gbl...
You can't.

Only client-side code can ask the client to do something. Now, you can
certainly have client code that "asks" the browser to open its default
mail client, and that *might* be Outlook, but again, it might not be.

And, for security reasons, JavaScript (the client code we're talking
about) has no abilities when it comes to the OS.

"andyoye" <an*****@nospam.comwrote in message
news:u7**************@TK2MSFTNGP03.phx.gbl...
How can I launch Outlook on users machines when they click a button on
a web form (InfoPath)?

Thanks




Jul 3 '08 #10
I'm trying to tell you that you CAN'T try to have a web page open Outlook on
the client. So, instead your code is attempting to open a copy of Outlook
that is on the server (if you are developing on a locally running web
server, then it is attempting to open Outlook on your machine. For security
reasons (which you are getting an exception describing), this is not
allowed.

Your code would work if you were running it in a Windows Forms application.

If you really need to have email sent from the web server, don't try to open
Outlook (which not everyone has anyway), but instead use the classes in
System.Web.Mail, which requires you provide it access to an SMTP server.
You create an instance of an email, configure it and send it - - no Outlook.

-Scott

"andyoye" <an*****@nospam.comwrote in message
news:ei**************@TK2MSFTNGP05.phx.gbl...
>I do want to open outlook, thats the MAIN objective here.

I ran below code:

Outlook.Application outlookApp = new Outlook.Application();

Outlook.MailItem message =

(Outlook.MailItem)outlookApp.CreateItem(Outlook.Ol ItemType.olMailItem);

message.Subject = "Hello World";

message.Recipients.Add(A@aol.com);

message.Body = "Hello. This is a test.";

I get below error when i try to run it.

System.Security.SecurityException
That assembly does not allow partially trusted callers.
at
System.Security.CodeAccessSecurityEngine.ThrowSecu rityException(Assembly
asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle
rmh, SecurityAction action, Object demand, IPermission permThatFailed)


"Duggi" <Du***************@gmail.comwrote in message
news:89**********************************@u12g2000 prd.googlegroups.com...
>On Jul 3, 5:59 pm, "andyoye" <andy...@nospam.comwrote:
>>How can I launch Outlook on users machines when they click a button on a
web
form (InfoPath)?

Thanks

I do not know why do you want to open outlook, however from
application programming side, the normal requirement is to mail
something to someone... In which case System.Web.Mail will help.

- Cnu


Jul 3 '08 #11
No, that's what I've been trying to tell you. See my newest post in the
thread for how to send an email from the server.
"andyoye" <an*****@nospam.comwrote in message
news:Ow**************@TK2MSFTNGP02.phx.gbl...
Yes it is a web form, but can the code launch Outlook on a user machine?
"Scott M." <s-***@nospam.nospamwrote in message
news:%2******************@TK2MSFTNGP05.phx.gbl...
>You're missing the point. The code you show below will only work if it
is *running* on a machine with Outlook installed. Since you said "web
form", then this could will be running on a web server and there are two
issues with that:

1. Most web servers don't have Outlook installed on them, nor would you
want to as it poses a security risk.
2. Even if the server had Outlook (or the Outlook Primary InterOp
Assembly - PIA), this code runs on the server and won't do anything for
the client.

-Scott

"andyoye" <an*****@nospam.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>>>I found following from
http://forums.devx.com/showthread.ph...hlight=outlook

looks like I am missing some namespace/referneces as
"Outlook.Application" could not be found.
Outlook.Application objOutlk = new Outlook.Application();
//Outlook
const int olMailItem = 0;
object objMail = new object();
objMail = objOutlk.CreateItem(olMailItem);
//Email item
objMail.To = emaila.Text;
objMail.cc = "";
//Enter an address here To include a carbon copy; bcc is For blind
carbon copy's
//Set up Subject Line
objMail.subject = "Quality Assurance Letter";
//To add an attachment, use:
//objMail.attachments.add("C:\MyAttachmentFile.txt")
string msg;
msg = "body test msg";
objMail.body = msg;
//Use this To display before sending, otherwise call objMail.Send to
send without reviewing
objMail.display();
//Use this To display before sending, otherwise call objMail.Send to
send without reviewing
//Clean up
objMail = null;
"Scott M." <s-***@nospam.nospamwrote in message
news:Op*************@TK2MSFTNGP04.phx.gbl...
You can't.

Only client-side code can ask the client to do something. Now, you can
certainly have client code that "asks" the browser to open its default
mail client, and that *might* be Outlook, but again, it might not be.

And, for security reasons, JavaScript (the client code we're talking
about) has no abilities when it comes to the OS.

"andyoye" <an*****@nospam.comwrote in message
news:u7**************@TK2MSFTNGP03.phx.gbl...
How can I launch Outlook on users machines when they click a button on
a web form (InfoPath)?
>
Thanks
>




Jul 3 '08 #12
Ok for point one, but about point 2, Andrew Whitechapel mentions that
ReleaseComObject is scoped to the AppDomain and using it, you risk causing
damage to other applications in the same AppDomain since the RCW is no
longer usable by any of the managed clients in the AppDomain. Furthermore,
you should loop until it returns 0, since sometimes, it may not return 0.
That is why he proposes the sequence I reproduced and conclude that "the
best practice guideline is to not use ReleaseComObject" (page 45, "Best
Practices")
Vanderghast, Access MVP
"Scott M." <s-***@nospam.nospamwrote in message
news:u9**************@TK2MSFTNGP02.phx.gbl...
Michael,

There are a couple of things wrong with this:

1. The OP asked about opening Outlook on the client but from Web Form
code, which can't be done.
2. Your clean up code is not correct.
a. When calling a COM object via COM InterOp, you must call the
Marshall class's ReleaseComObject method, which tells the CLR to release
it connection to the underlying COM object. Since COM objects are freed
from memory when their reference count goes to zero, this step is critical
otherwise the object will persist in memory even though the .NET program
that called it no longer has any reference to it.
b. You really should not ever need to call GC anything except for
under very special circumstances. The GC runs in a separate thread from
your .NET application and the moment you call GC from your application,
you force it to operate in the same thread as your main application. This
can actually result in your application's performance degrading. The
bottom line is that the GC works quite well all on its own and you really
shouldn't interfere with its normal operations because you will most
likely not improve matters.

The correct way to "clean up" a COM object from .NET is this:

objOutlook.Quit();
System.Marshall.ReleaseComObjct(objOutlook);
objOutlook = null;

-Scott

Jul 3 '08 #13
It seems to me that this relates to writing Office add-in's via VSTO, which
is not the situation here.

When an Office applicatoin (such as Outlook) has an add-in written in .NET.
It runs within the context of the hosted CLR, so an AppDomain is created for
the add-in to run in.. When the add-in has completed its work, the
AppDomain within the hosted CLR ends, and thus the need to do any releasing
of COM objects (or GC cleanup for that matter), is moot.

The OP is not talking about this situation. AFAIK and based on everything
that I've read since 2002, is that when utilizing a COM object within the
context of a managed application (.NET Windows or ASP .NET), you MUST call
ReleaseCOMObject. This is because the situation is reversed. The RCW
exists in the SAME AppDomain as the main application, so just finishing the
work with the COM object won't mean the end of the AppDomain (because your
..NET application will still be running).

Think about this for a moment (or actually build a simple RCW project and
see for yourself).

1. The .NET code creates an instance of a COM object. This causes 3 items
to go into memory.
a. A variable on the managed stack.
b. A RCW instance on the managed heap (pointed to by the variable
mentioned above).
c. The COM object is instantiated and is in memory on the unmanaged
heap.

2. When your .NET application calls the .Quit() method of the COM object,
the program's UI may close, but the actual process remains in memory. Try
this yourself. You'll see that just calling .Quit() doesn't kill the
process (use the Task Manager to verify that the COM object's process is
still running).

3. If you call Marshall.ReleaseComObject(obj), you instruct the CLR to
release its (for lack of a better term) reference to the COM object on the
unmanaged heap, thus reducing its reference count to zero. In the COM
world, that is when the object is removed from memory.

4. Now that the underlying COM object has been successfully unloaded, we
still have our variable on the managed stack and our RCW on the managed
heap. At this point, it's .NET memory management as usual. You can set
your variable to null (Nothing in VB) if you like, but for a local variable,
that may not accomplish much, sice the variable will fall off the stack at
the end of the procedure anyway. Still though, it's not a bad practice to
do it.

5. Now we're just left with a managed object on the managed heap with no
references to it and the GC will clean it up if and when it deems it
necessary. No need to get the GC involved.

-Scott
"Michel Walsh" <vanderghast@VirusAreFunnierThanSpamwrote in message
news:OH**************@TK2MSFTNGP05.phx.gbl...
Ok for point one, but about point 2, Andrew Whitechapel mentions that
ReleaseComObject is scoped to the AppDomain and using it, you risk causing
damage to other applications in the same AppDomain since the RCW is no
longer usable by any of the managed clients in the AppDomain. Furthermore,
you should loop until it returns 0, since sometimes, it may not return 0.
That is why he proposes the sequence I reproduced and conclude that "the
best practice guideline is to not use ReleaseComObject" (page 45, "Best
Practices")
Vanderghast, Access MVP
"Scott M." <s-***@nospam.nospamwrote in message
news:u9**************@TK2MSFTNGP02.phx.gbl...
>Michael,

There are a couple of things wrong with this:

1. The OP asked about opening Outlook on the client but from Web Form
code, which can't be done.
2. Your clean up code is not correct.
a. When calling a COM object via COM InterOp, you must call the
Marshall class's ReleaseComObject method, which tells the CLR to release
it connection to the underlying COM object. Since COM objects are freed
from memory when their reference count goes to zero, this step is
critical otherwise the object will persist in memory even though the .NET
program that called it no longer has any reference to it.
b. You really should not ever need to call GC anything except for
under very special circumstances. The GC runs in a separate thread from
your .NET application and the moment you call GC from your application,
you force it to operate in the same thread as your main application.
This can actually result in your application's performance degrading.
The bottom line is that the GC works quite well all on its own and you
really shouldn't interfere with its normal operations because you will
most likely not improve matters.

The correct way to "clean up" a COM object from .NET is this:

objOutlook.Quit();
System.Marshall.ReleaseComObjct(objOutlook);
objOutlook = null;

-Scott


Jul 3 '08 #14
Just one correction. "mailto:" doesn't send mail. It simply asks the
client to open its default mail client and prepares an email message. It
doesn't cause the message to be sent. Furthermore, since many people use
web-based mail, rather than an email client, using mailto: can cause a
client that does not even have an email account set up on it to open. The
user would then have to set up their client with an email account before
they could hit Send.

To be sure, if you want to have your .NET program send mail, you should
either use the Systsem.Web.Mail namespace and create a message on the server
and have the server send the message via an SMTP server or you could CDO to
go against an Exchange Sever and automate the process that way - -
System.Web.Mail is MUCH simpler.

-Scott
"Family Tree Mike" <Fa************@discussions.microsoft.comwrote in
message news:8A**********************************@microsof t.com...
No.

Read the whole thread though. I've got to believe that understanding
"mailto:..." is what you need.

The person who posted the code wrote: "this should spawn on the client
machine not the web server. but then again im using an all in one so
....".

This means they were testing from the server itself. The code works fine
in a windows application. The permission errors you refered to in another
email likely are that the ASP.Net account doesn't have permission to run
outlook. Don't give it permision though...

"andyoye" wrote:
>Yes it is a web form, but can the code launch Outlook on a user machine?
"Scott M." <s-***@nospam.nospamwrote in message
news:%2******************@TK2MSFTNGP05.phx.gbl. ..
You're missing the point. The code you show below will only work if it
is
*running* on a machine with Outlook installed. Since you said "web
form",
then this could will be running on a web server and there are two
issues
with that:

1. Most web servers don't have Outlook installed on them, nor would you
want to as it poses a security risk.
2. Even if the server had Outlook (or the Outlook Primary InterOp
Assembly - PIA), this code runs on the server and won't do anything for
the client.

-Scott

"andyoye" <an*****@nospam.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
I found following from
http://forums.devx.com/showthread.ph...hlight=outlook

looks like I am missing some namespace/referneces as
"Outlook.Application" could not be found.
Outlook.Application objOutlk = new Outlook.Application();
//Outlook
const int olMailItem = 0;
object objMail = new object();
objMail = objOutlk.CreateItem(olMailItem);
//Email item
objMail.To = emaila.Text;
objMail.cc = "";
//Enter an address here To include a carbon copy; bcc is For blind
carbon
copy's
//Set up Subject Line
objMail.subject = "Quality Assurance Letter";
//To add an attachment, use:
//objMail.attachments.add("C:\MyAttachmentFile.txt")
string msg;
msg = "body test msg";
objMail.body = msg;
//Use this To display before sending, otherwise call objMail.Send to
send
without reviewing
objMail.display();
//Use this To display before sending, otherwise call objMail.Send to
send
without reviewing
//Clean up
objMail = null;
"Scott M." <s-***@nospam.nospamwrote in message
news:Op*************@TK2MSFTNGP04.phx.gbl...
You can't.

Only client-side code can ask the client to do something. Now, you
can
certainly have client code that "asks" the browser to open its
default
mail client, and that *might* be Outlook, but again, it might not be.

And, for security reasons, JavaScript (the client code we're talking
about) has no abilities when it comes to the OS.

"andyoye" <an*****@nospam.comwrote in message
news:u7**************@TK2MSFTNGP03.phx.gbl...
How can I launch Outlook on users machines when they click a button
on
a web form (InfoPath)?

Thanks





Jul 3 '08 #15
Here's an interesting thread discussing this topic and making it clear that
what you describe is a VSTO thing and not applicable to general .NET
development. As a matter of fact, this thread says that even in VSTO, you
should still call ReleaseComObject beacuse older versions of Office won't
respond the same way Office 2003 and above do.

-Scott
"Michel Walsh" <vanderghast@VirusAreFunnierThanSpamwrote in message
news:OH**************@TK2MSFTNGP05.phx.gbl...
Ok for point one, but about point 2, Andrew Whitechapel mentions that
ReleaseComObject is scoped to the AppDomain and using it, you risk causing
damage to other applications in the same AppDomain since the RCW is no
longer usable by any of the managed clients in the AppDomain. Furthermore,
you should loop until it returns 0, since sometimes, it may not return 0.
That is why he proposes the sequence I reproduced and conclude that "the
best practice guideline is to not use ReleaseComObject" (page 45, "Best
Practices")
Vanderghast, Access MVP
"Scott M." <s-***@nospam.nospamwrote in message
news:u9**************@TK2MSFTNGP02.phx.gbl...
>Michael,

There are a couple of things wrong with this:

1. The OP asked about opening Outlook on the client but from Web Form
code, which can't be done.
2. Your clean up code is not correct.
a. When calling a COM object via COM InterOp, you must call the
Marshall class's ReleaseComObject method, which tells the CLR to release
it connection to the underlying COM object. Since COM objects are freed
from memory when their reference count goes to zero, this step is
critical otherwise the object will persist in memory even though the .NET
program that called it no longer has any reference to it.
b. You really should not ever need to call GC anything except for
under very special circumstances. The GC runs in a separate thread from
your .NET application and the moment you call GC from your application,
you force it to operate in the same thread as your main application.
This can actually result in your application's performance degrading.
The bottom line is that the GC works quite well all on its own and you
really shouldn't interfere with its normal operations because you will
most likely not improve matters.

The correct way to "clean up" a COM object from .NET is this:

objOutlook.Quit();
System.Marshall.ReleaseComObjct(objOutlook);
objOutlook = null;

-Scott


Jul 3 '08 #16
Sorry! Here's the link:

http://www.add-in-express.com/forum/...FID=5&TID=2523

-Scott

"Michel Walsh" <vanderghast@VirusAreFunnierThanSpamwrote in message
news:OH**************@TK2MSFTNGP05.phx.gbl...
Ok for point one, but about point 2, Andrew Whitechapel mentions that
ReleaseComObject is scoped to the AppDomain and using it, you risk causing
damage to other applications in the same AppDomain since the RCW is no
longer usable by any of the managed clients in the AppDomain. Furthermore,
you should loop until it returns 0, since sometimes, it may not return 0.
That is why he proposes the sequence I reproduced and conclude that "the
best practice guideline is to not use ReleaseComObject" (page 45, "Best
Practices")
Vanderghast, Access MVP
"Scott M." <s-***@nospam.nospamwrote in message
news:u9**************@TK2MSFTNGP02.phx.gbl...
>Michael,

There are a couple of things wrong with this:

1. The OP asked about opening Outlook on the client but from Web Form
code, which can't be done.
2. Your clean up code is not correct.
a. When calling a COM object via COM InterOp, you must call the
Marshall class's ReleaseComObject method, which tells the CLR to release
it connection to the underlying COM object. Since COM objects are freed
from memory when their reference count goes to zero, this step is
critical otherwise the object will persist in memory even though the .NET
program that called it no longer has any reference to it.
b. You really should not ever need to call GC anything except for
under very special circumstances. The GC runs in a separate thread from
your .NET application and the moment you call GC from your application,
you force it to operate in the same thread as your main application.
This can actually result in your application's performance degrading.
The bottom line is that the GC works quite well all on its own and you
really shouldn't interfere with its normal operations because you will
most likely not improve matters.

The correct way to "clean up" a COM object from .NET is this:

objOutlook.Quit();
System.Marshall.ReleaseComObjct(objOutlook);
objOutlook = null;

-Scott


Jul 3 '08 #17
Thanks for the link.

"Scott M." <s-***@nospam.nospamwrote in message
news:u9*************@TK2MSFTNGP04.phx.gbl...
Sorry! Here's the link:

http://www.add-in-express.com/forum/...FID=5&TID=2523

-Scott
Jul 4 '08 #18
andyoye wrote:
How can I launch Outlook on users machines when they click a button on a web
form (InfoPath)?
There is no way to open Outlook directly from the HTML of a web page,
nor from the C# "code behind" which is executed on the server running IIS.

If, however, you are programming for your own intranet, or can guarantee
that the user is running IE and will execute code from your site with
enough privelege, you can write an embedded activeX control and call it
from javascript within your page. Because the ActiveX control will
download to the client and run there, you can do more or less anything
you could do in a normal user program.

Of course, if you write the ActiveX control in C#, you're dependent on
the correct version of .NET already being installed on the client
machine, too.
Jul 4 '08 #19
You cannot create ActiveX controls using .NET. An ActiveX control is a
compiled COM application that downloads to the user's client browser and
attempts to execute there. There is no such equivelent in .NET.

"John Daragon" <jo**@argv.co.ukwrote in message
news:48**********************@news.zen.co.uk...
andyoye wrote:
>How can I launch Outlook on users machines when they click a button on a
web form (InfoPath)?

There is no way to open Outlook directly from the HTML of a web page, nor
from the C# "code behind" which is executed on the server running IIS.

If, however, you are programming for your own intranet, or can guarantee
that the user is running IE and will execute code from your site with
enough privelege, you can write an embedded activeX control and call it
from javascript within your page. Because the ActiveX control will
download to the client and run there, you can do more or less anything you
could do in a normal user program.

Of course, if you write the ActiveX control in C#, you're dependent on the
correct version of .NET already being installed on the client machine,
too.

Jul 4 '08 #20
Scott M. wrote:
You cannot create ActiveX controls using .NET. An ActiveX control is a
compiled COM application that downloads to the user's client browser and
attempts to execute there. There is no such equivelent in .NET.

"John Daragon" <jo**@argv.co.ukwrote in message
news:48**********************@news.zen.co.uk...
>andyoye wrote:
>>How can I launch Outlook on users machines when they click a button on a
web form (InfoPath)?
There is no way to open Outlook directly from the HTML of a web page, nor
from the C# "code behind" which is executed on the server running IIS.

If, however, you are programming for your own intranet, or can guarantee
that the user is running IE and will execute code from your site with
enough privelege, you can write an embedded activeX control and call it
from javascript within your page. Because the ActiveX control will
download to the client and run there, you can do more or less anything you
could do in a normal user program.

Of course, if you write the ActiveX control in C#, you're dependent on the
correct version of .NET already being installed on the client machine,
too.

Oh yes there is. I've written them.

Jul 5 '08 #21

"John Daragon" <jo**@argv.co.ukwrote in message
news:48**********************@news.zen.co.uk...
Oh yes there is. I've written them.
No, you haven't. You can write .NET components that expose themselves to
COM via InterOp. But, the .NET Framework does not emit native ActiveX
components (which are COM objects).


Jul 5 '08 #22
Scott M. wrote:
"John Daragon" <jo**@argv.co.ukwrote in message
news:48**********************@news.zen.co.uk...
>Oh yes there is. I've written them.

No, you haven't. You can write .NET components that expose themselves to
COM via InterOp. But, the .NET Framework does not emit native ActiveX
components (which are COM objects).
Oh, for heaven's sake... The difference (in this context) is ?
Jul 5 '08 #23
The difference is that you are telling the OP that you can do something that
you can't.

If you don't even know what technology you are using, how can you be of
help? Your advice is just going to confuse matters for someone who
obviously is new to .NET development.
"John Daragon" <jo**@argv.co.ukwrote in message
news:48**********************@news.zen.co.uk...
Scott M. wrote:
>"John Daragon" <jo**@argv.co.ukwrote in message
news:48**********************@news.zen.co.uk...
>>Oh yes there is. I've written them.

No, you haven't. You can write .NET components that expose themselves to
COM via InterOp. But, the .NET Framework does not emit native ActiveX
components (which are COM objects).

Oh, for heaven's sake... The difference (in this context) is ?

Jul 6 '08 #24

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Daniel Pope | last post by:
Hello Everybody, I'm preparing for doing a daunting task: to access Out look Microsoft Outlook Express(regardles the operating system and Outlook version) from a Java applet (after the client...
4
by: lauren quantrell | last post by:
Is there a way to open the MS Outlook address book using VBA and then be able to do something with the return value? I want users to click an icon to open the Outlook address book then when an...
5
by: Siv | last post by:
Hi, A little while ago I asked if anyone could help me with how to create an email using MS Outlook that contained an embedded picture file. Thanks to Jay Harlow I was able to get this working...
2
by: Snig | last post by:
Hi I'm into creating a web application in C# (.NET Framework 1.1) which would list and manage the outlook tasks. If I try to do this in a Windows Application, it works fine. But there are...
6
by: Brad | last post by:
I have a win2003 server workstation with multiple webs, each web has it's own ip address. In VS2005, if I select to open an existing web site, select Local IIS, the dialog correctly displays a...
3
by: bobdydd | last post by:
Hi Everybody Access 2000, Outlook 2000 Windows XP I am running the code below to open Microsoft Outlook from a Command Button. It works fine until I tried it on a machine that has Office...
14
by: C | last post by:
Hi, From my ASP.NET application when the user clicksa button I want to be able to programmatically open Outlook, create a new mail, add attachments and set the body text. Is this possible? ...
1
by: keri | last post by:
Hi, I use the below for the user to view their outlook calendar Sub DisplayInbox() Dim myolApp As Outlook.Application Dim myNameSpace As Outlook.NameSpace Dim myFolder As Outlook.MAPIFolder...
5
by: John | last post by:
Hi I have an Outlook add-in solution which includes a setup project. If I install the Outlook add-in by right clicking on the setup project and sleeting Install then the add-in gets installed...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.