Here I'm using WebApi I want an image for sending Email For that I wrote the code as:
var files = HttpContext.Current.Request.Files;
if (files.Count > 0) {
for (int i = 0; i < files.Count; i++) {
HttpPostedFile file = files[i];
mailModel.filename = file.FileName;
mailModel.filecontent = file.InputStream;
}
}
Here How can i Bind mailModel.Filecontent
My Class File as
public class SendMailRequest
{
public string filecontent { get; set; }
public string filename { get; set; }
}
My Mail Sending Code is:
if (mailModel.filename != null) {
string tempPath = WebConfigurationManager.AppSettings["TempFile"];
string filePath = Path.Combine(tempPath, mailModel.filename);
using(System.IO.FileStream reader = System.IO.File.Create(filePath)) {
byte[] buffer = Convert.FromBase64String(mailModel.filecontent);
reader.Write(buffer, 0, buffer.Length);
reader.Dispose();
}
msg.Attachments.Add(new Attachment(filePath));
How can I Bind my File to the FileContent?