Subject: Defining a process
Posted By: snufse Post Date: 4/17/2008 10:11:44 AM
Can someone tell me what the syntax is for defining a process. Below code (calls outlook with an attachment)is taken from a current windows application, but I cannot determine what an equivalent would be in asp. Thank you.

Dim prc As New Process
prc.StartInfo = New ProcessStartInfo("outlook.exe", "/a " + ControlChars.Quote & myFilePath & ControlChars.Quote)
prc.Start()


Reply By: snufse Reply Date: 4/17/2008 11:35:10 AM
I figured it out, here is the code for displaying a Crystal Report and having an "Email' button that will call outlook with the document as an attachment:


Protected Sub EmailButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles EmailButton.Click

        Dim myFileName As String = String.Format("\{0:yyyyMMdd_HHmmss}.doc", Date.Now)
        Dim myFilePath As String = "c:\windows\temp" + myFileName

        myCrystalReport.ExportToDisk(ExportFormatType.WordForWindows, myFilePath)

        Try
            Dim myProcess As System.Diagnostics.Process = New System.Diagnostics.Process()
            myProcess.StartInfo = New Diagnostics.ProcessStartInfo("outlook.exe", "/a " + ControlChars.Quote & myFilePath & ControlChars.Quote)
            myProcess.Start()
        Catch ex As Exception
            ErrorString = ex.ToString
            ASPNET_MsgBox("An error has occurred sending email: " + vbCrLf + ErrorString)
        End Try

    End Sub


Reply By: gbianchi Reply Date: 4/17/2008 11:41:04 AM
Hi there.. Just a question about your code. (to clarify)

This code start the proccess in the client machine or in the server? Since the code is executing in the server, did you try it out in a web enviroment? (I mean, running from another PC?) Also, what happens if the client doesn't have outlook?

HTH

Gonzalo

===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
===========================================================
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
===========================================================
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles/Classics-Week-I-Hate-You.aspx
===========================================================
Reply By: Imar Reply Date: 4/17/2008 11:56:39 AM
Ouch.... I think this code will earn you the "works on my machine" award from Gonzalo's signature....

As Gonzalo pointed out, this code runs on the server. It's not at all recommended to have web applications run client applications like this. What happens when you have 100 concurrent users? You'll end up with 100 instances of Outlook.

Also, who's going to enter the To address and press the Send button?

Are you running this on your local machine? If so, just for fun, try accessing the web site from a different machine. That will give you a clearer idea of what the server is, and what the client.

Finally, look at the System.Net.Mail namespace. It has all the functionality you need to send e-mail; with attachments as the following simple example demonstrates:
MailMessage myMessage = new MailMessage();
myMessage.From = new MailAddress("you@yourprovider.com");
myMessage.To.Add(new MailAddress("them@theirprovider.com"));
myMessage.Attachments.Add(new Attachment(@"D:\SomeFile.txt"));
new SmtpClient("Your.Mail.Server").Send(myMessage);
Hope this helps,

Imar



---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
Reply By: snufse Reply Date: 4/23/2008 6:50:54 AM
The code runs on the server. This is an intranet app and all the clients have outlook. The max user will be about 10. The reason for calling Outlook is to have the user enter the distribution list and any comments or notes as this may vary.

Reply By: Imar Reply Date: 4/23/2008 7:13:40 AM
This code runs on the server so whether the client has Outlook or not is irrelevant. This code never reaches the client....

If you insist to use Outlook on the client (not recommended), you need to look into client side automation of Outlook using VBScript / JavaScript or other means like ActiceX

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.

Go to topic 70807

Return to index page 2
Return to index page 1