By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,571 Members | 3,168 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,571 IT Pros & Developers. It's quick & easy.

System.Diagnostics.Process.Start c# query

P: n/a
Hi All,

I am using c# to build an application. I want a button that will be able to
open a new mail message with an attachment. The new mail message works but I
can't get the attachment to work - there is no error message just no
attachment. Any ideas? Code i am using is;

System.Diagnostics.Process.Start("mailto:em***@ema il.com?subject=Software&body=see attachment&attachment=c:/myview.mht");

Thanks
Jan 4 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On 4 Jan, 11:44, JimJob <Jim...@discussions.microsoft.comwrote:
Hi All,

I am using c# to build an application. I want a button that will be able to
open a new mail message with an attachment. *The new mail message works but I
can't get the attachment to work - there is no error message just no
attachment. *Any ideas? *Code i am using is;

System.Diagnostics.Process.Start("mailto:em...@ema il.com?subject=Software&body=see attachment&attachment=c:/myview.mht");

Thanks
try c:\ and prefix the string with an @

ie

(@"mailto:em...@email.com?subject=Software&body=se e
attachment&attachment=c:\myview.mht"

@ will stop the compiler treating \ as an escape character.
Jan 4 '08 #2

P: n/a
Thanks developer - but no joy. I have also tried @ C:\ or C:/ to no avail

"DeveloperX" wrote:
On 4 Jan, 11:44, JimJob <Jim...@discussions.microsoft.comwrote:
Hi All,

I am using c# to build an application. I want a button that will be able to
open a new mail message with an attachment. The new mail message works but I
can't get the attachment to work - there is no error message just no
attachment. Any ideas? Code i am using is;

System.Diagnostics.Process.Start("mailto:em...@ema il.com?subject=Software&body=see attachment&attachment=c:/myview.mht");

Thanks

try c:\ and prefix the string with an @

ie

(@"mailto:em...@email.com?subject=Software&body=se e
attachment&attachment=c:\myview.mht"

@ will stop the compiler treating \ as an escape character.
Jan 4 '08 #3

P: n/a
Hi,

I'm not sure if you can do it. mailto is intended to be used from a webpage,
there is no way to attach a local file from a webpage's link

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
"JimJob" <Ji****@discussions.microsoft.comwrote in message
news:55**********************************@microsof t.com...
Hi All,

I am using c# to build an application. I want a button that will be able
to
open a new mail message with an attachment. The new mail message works
but I
can't get the attachment to work - there is no error message just no
attachment. Any ideas? Code i am using is;

System.Diagnostics.Process.Start("mailto:em***@ema il.com?subject=Software&body=see
attachment&attachment=c:/myview.mht");

Thanks

Jan 4 '08 #4

P: n/a
On 4 Jan, 13:59, JimJob <Jim...@discussions.microsoft.comwrote:
Thanks developer - but no joy. *I have also tried @ C:\ or C:/ to no avail

"DeveloperX" wrote:
On 4 Jan, 11:44, JimJob <Jim...@discussions.microsoft.comwrote:
Hi All,
I am using c# to build an application. I want a button that will be able to
open a new mail message with an attachment. *The new mail message works but I
can't get the attachment to work - there is no error message just no
attachment. *Any ideas? *Code i am using is;
System.Diagnostics.Process.Start("mailto:em...@ema il.com?subject=Software&body=see attachment&attachment=c:/myview.mht");
Thanks
try c:\ and prefix the string with an @
ie
(@"mailto:em...@email.com?subject=Software&body=se e
attachment&attachment=c:\myview.mht"
@ will stop the compiler treating \ as an escape character.- Hide quotedtext -

- Show quoted text -
Ignacio appears to be correct, my apologies. You could always add a
reference to System.Web.Mail and use the classes in there. having a
quick poke, I got:

using System.Web.Mail;
MailMessage message = new MailMessage();
message.From = "pe****@place.com";
message.Body = "body";
message.To ="anotherpe****@place.com";
message.Subject = "subject";
message.Attachments.Add(new MailAttachment(@"C:\boot.ini"));
SmtpMail.SmtpServer = "smtp.mailserver.com";
SmtpMail.Send(message);

should do it, but if you get a "CDO.message not found" message that's
to do with authentication. (I got that error, there seem to be alot of
posts about it!)
alternatively I managed to get this to work using outlook interop, but
again, outlook now has all that cruddy security so it pops up a dialog
saying is this ok?? I'm sure I've read about ways of disabling that,
but it was a while ago.

using Microsoft.Office.Interop.Outlook;
Microsoft.Office.Interop.Outlook.Application app =
new Microsoft.Office.Interop.Outlook.ApplicationClass( );
MailItem message = (MailItem)app.CreateItem(OlItemType.olMailItem);

Recipient recip =
(Recipient)message.Recipients.Add("pe****@place.co m");
recip.Resolve();

message.Body = "body";
message.Subject = "subject";
message.Attachments.Add(@"C:\boot.ini",
OlAttachmentType.olByValue,message.Body.Length + 1, "an attachment");
//message.Save();
//message.Display(false);
message.Send();
probably no help, but you never know.
Jan 4 '08 #5

P: n/a
Thanks Developer - I am attempting to to try your second solution - however
it dosent like "using Microsoft.Office.Interop.Outlook;" am i missing a
required reference? Asking permission to use outlook wont cause a problem
for me.

I tried the System.Web.Mail method and that works fine - but I would prefer
that on the click of a button a new mail message window opens with the
attachement and the user then inputs what they want and then click on send.
Rather then a message being sent in the back ground with no user interaction
which is the case of the System.Web.Mail .

I feel i am getting close to the solution.....thought it would be easier
though!

Thanks

"DeveloperX" wrote:
On 4 Jan, 13:59, JimJob <Jim...@discussions.microsoft.comwrote:
Thanks developer - but no joy. I have also tried @ C:\ or C:/ to no avail

"DeveloperX" wrote:
On 4 Jan, 11:44, JimJob <Jim...@discussions.microsoft.comwrote:
Hi All,
I am using c# to build an application. I want a button that will be able to
open a new mail message with an attachment. The new mail message works but I
can't get the attachment to work - there is no error message just no
attachment. Any ideas? Code i am using is;
System.Diagnostics.Process.Start("mailto:em...@ema il.com?subject=Software&body=see attachment&attachment=c:/myview.mht");
Thanks
try c:\ and prefix the string with an @
ie
(@"mailto:em...@email.com?subject=Software&body=se e
attachment&attachment=c:\myview.mht"
@ will stop the compiler treating \ as an escape character.- Hide quoted text -
- Show quoted text -

Ignacio appears to be correct, my apologies. You could always add a
reference to System.Web.Mail and use the classes in there. having a
quick poke, I got:

using System.Web.Mail;
MailMessage message = new MailMessage();
message.From = "pe****@place.com";
message.Body = "body";
message.To ="anotherpe****@place.com";
message.Subject = "subject";
message.Attachments.Add(new MailAttachment(@"C:\boot.ini"));
SmtpMail.SmtpServer = "smtp.mailserver.com";
SmtpMail.Send(message);

should do it, but if you get a "CDO.message not found" message that's
to do with authentication. (I got that error, there seem to be alot of
posts about it!)
alternatively I managed to get this to work using outlook interop, but
again, outlook now has all that cruddy security so it pops up a dialog
saying is this ok?? I'm sure I've read about ways of disabling that,
but it was a while ago.

using Microsoft.Office.Interop.Outlook;
Microsoft.Office.Interop.Outlook.Application app =
new Microsoft.Office.Interop.Outlook.ApplicationClass( );
MailItem message = (MailItem)app.CreateItem(OlItemType.olMailItem);

Recipient recip =
(Recipient)message.Recipients.Add("pe****@place.co m");
recip.Resolve();

message.Body = "body";
message.Subject = "subject";
message.Attachments.Add(@"C:\boot.ini",
OlAttachmentType.olByValue,message.Body.Length + 1, "an attachment");
//message.Save();
//message.Display(false);
message.Send();
probably no help, but you never know.
Jan 4 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.