1

I am coding in C# with .Net. I am trying to send an email with a PDF attachment. My current problem is that I don't know how to get the PDF from my local computer to send with the email.

Am I supposed to use the location of my computer in the (@"d:\1.txt") portion of the code?

this is the code I currently have

MailMessage msg = new MailMessage();

Aspose.Email.Attachment attachment;
attachment = new Aspose.Email.Attachment(@"d:\1.txt");
msg.Attachments.Add(attachment);
  • You need to get the bytes to send as an attachment: https://stackoverflow.com/questions/2451864/c-sharp-4-0-convert-pdf-to-byte-and-vice-versa – GH DevOps Sep 01 '22 at 16:38
  • Ah I see thanks! Is there a way to have a PDF file sent by email without doing it from my local computer? –  Sep 01 '22 at 16:48
  • Like I don't want to have my local path shown in code –  Sep 01 '22 at 16:48
  • You can use a memory stream to get the bytes. – GH DevOps Sep 01 '22 at 17:05
  • is this is web page? Then code behind is not able to touch, get, grab ANY files from the local computer. If you come to my web site, you think my site can go mess around and grab any file on your computer -- including ones called banking information, or grab files on your computer called MyPasswords? The file system on each computer using a web browser is off limits from your code behind on the web site. If this was not the case, the internet would be such a huge security risk, since every web site would grab and take files from your computer. You have to up-load that file to the web site. – Albert D. Kallal Sep 01 '22 at 18:03
  • Ah you are so right....don't know why that did not cross my mind. Thank you so much Albert. Is there an asp.net official link on how to upload files on a site? –  Sep 01 '22 at 20:27
  • Uploading is rather common. You can drop in a file upload, or perhaps use a fancy uploader with say a drag and drop area. So really a question from simple or something fancy. – Albert D. Kallal Sep 02 '22 at 05:48

0 Answers0