Правильный способ передачи содержимого FileUpload в [WebMethod]?
У меня есть [WebMethod] Sendemail. Это отлично работает, но теперь я хочу обновить его, чтобы отправить вложения. Я использую файл загрузки. Это мой метод Call.
<code>lblEmailSent.Text = Send.Sendemail(txtTo.Text, txtSubject.Text, txtbody.Text, FileUpload1.PostedFile.FileName, FileUpload1.FileContent); </code>
Мое заявление о вызове подчеркнуто синим цветом, а две приведенные ошибки выглядят следующим образом:
*1)*The best overloaded method match for 'WebTestServiceApp.localhost.Service1.Sendemail(string, string, string, string, WebTestServiceApp.localhost.Stream)' has some invalid arguments
*2)*Argument 5: cannot convert from 'System.IO.Stream' to 'WebTestServiceApp.localhost.Stream'
FileUpload1.PostedFile.FileName передается как строка. FileUpload1.FileContent передается как поток.
Это мой [WebMethod], теперь вы все можете видеть все, что я вижу, я не могу определить, что что-то не так, но я не уверен, должен ли FileUpload1.FileContent передаваться как поток.
<code>[WebMethod] public string Sendemail(String inValueTo, String inValueSub, String inValueBody, String inValueAttachmentPostedfile, Stream inValueAttachemtnFileContent) //, String inValueAttachmentPostedfile, Stream inValueAttachemtnFileContent { try { String valueTo = inValueTo; String valueSub = inValueSub; String valueBody = inValueBody; String valueAttachmentPostedfile = inValueAttachmentPostedfile; //FileUpload1.PostedFile.FileName Stream valueAttachmentFileContent = inValueAttachemtnFileContent; //FileUpload1.FileContent.fileName System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); // Creating new message. message.To.Add(valueTo); message.Subject = valueSub; message.From = new System.Net.Mail.MailAddress("[email protected]"); message.Body = valueBody; message.IsBodyHtml = true; string fileName = Path.GetFileName(valueAttachmentPostedfile); // Get attachment file Attachment myAttachment = new Attachment(valueAttachmentFileContent, fileName); if (fileName != "") { message.Attachments.Add(myAttachment); // Send attachment } System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com"); //Properties.Settings.Default.MailSMTPServer smtp.Port = 587; smtp.EnableSsl = true; smtp.UseDefaultCredentials = false; NetworkCredential netC = new NetworkCredential(Properties.Settings.Default.username, Properties.Settings.Default.password); // Useing Projects defult settings. smtp.Credentials = netC; smtp.Send(message); return "Message has been sent"; } catch (Exception) { return "Message faild to send" ; } } </code>