Sending Mail With Attachment With Web Service Problem

yccheok used Ask the Experts™
i had host a email web service on a win2000 server. one of the parameter of the web service method call is "string filename". this "filename" will passed into

System.Web.Mail.MailAttachment class constructor to send email.

now, i have another standalone application which run on win98 computer. my standalone application want to send a image file which located in win98 computer.

can i just call the web service ws.SendMail("", "c:\live.jpg"); without first explicit transfer the image file to win2000 server?

thank you.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
No, you must first transfer the attachment to the win2000 server.

You could read the image into a byte array and send it as a separate parameter in your web service call.  Your web service can then save it back to a file and attach it to the email.  Something like...

using System.IO;
public void SendMail (string pUserName, string pFileName)
System.IO.FileStream sSource = System.IO.File.Open (pFileName, FileMode.Open, FileAccess.Read);
readLen = System.Convert.ToInt32 (sSource.Length);
byte [] rdBuf = new byte[readLen]; //create buffer
sSource.Read (rdBuf, 0, readLen); //read entire file into buffer
Service1 ws = new Service1(); //create web service proxy
ws.SendMail (pUserName, rdBuf, pFileName); //call web service

//Web Service
using System.IO;
public void SendMail (string pUserName, byte [] pAttachment, string pOriginalFileName)
//Note:  you need to save the file to some "common" location on the server before you
//can attach it to the e-mail
int pos = 0;
pos = pOriginalFileName.LastIndexOf ("\\");
sAttachmentTarget =  "c:\temp\" + pOriginalFileName.SubString (pos);
FileStream sTarget = new FileStream (sAttachmentTarget, FileMode.Create); //create target file
MemoryStream msTarget = new MemoryStream (pAttachment); //convert byte array to stream
msTarget.WriteTo (pTarget); //write stream to target
//code to attach the sAttachmentTarget to an email and send the email

or you could use a 3rd party control such as aspUpload to transfer the attachment for you ... much easier :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial