A maneira correta de passar o conteúdo do FileUpload para [WebMethod]?
Eu tenho um [WebMethod] Sendemail Isso funciona bem, mas agora eu o que atualizá-lo para enviar anexos. Eu estou usando um upload de arquivo. Este é o meu método.
<code>lblEmailSent.Text = Send.Sendemail(txtTo.Text, txtSubject.Text, txtbody.Text, FileUpload1.PostedFile.FileName, FileUpload1.FileContent); </code>
Minha declaração de chamada é sublinhada em azul e os dois erros apresentados são semelhantes:
*1)* A melhor correspondência de método sobrecarregado para 'WebTestServiceApp.localhost.Service1.Sendemail (string, string, string, string, WebTestServiceApp.localhost.Stream)' possui alguns argumentos inválidos
*2)* Argumento 5: não é possível converter de 'System.IO.Stream' para 'WebTestServiceApp.localhost.Stream'
FileUpload1.PostedFile.FileName é passado como um String FileUpload1.FileContent é passado como um fluxo
Este é o meu [WebMethod], Agora você pode ver tudo o que eu posso ver, não consigo detectar nada de errado, mas não tenho certeza se o FileUpload1.FileContent deve ser passado como Stream.
<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>