I am using the following code for receiving information from users, is it possible to get all the information as a PDF attachment ?

protected void Button1_Click(object sender, EventArgs e)
    {
        SmtpClient smtpClient = new SmtpClient();
        MailMessage message = new MailMessage();
        message.To.Add("admin@domain.com");
        if (CheckBox1.Checked == true)
        {
            emailadd.Text = employeenameDropDown.SelectedValue;

            message.Bcc.Add(emailadd.Text);

        }
        message.Subject = "Timesheet " + employeenameDropDown.SelectedItem;
        message.IsBodyHtml = true;
        message.Body = "<h3>Timesheet</h3>" + System.Environment.NewLine + System.Environment.NewLine + "<br/>";
        message.Body += "<b>Name: </b>" + employeenameDropDown.SelectedItem + "<br/>" + "<br/>";
        smtpClient.EnableSsl = true;
        smtpClient.Send(message);
        EmailSentForm.Visible = Visible;
        employeenameDropDown.Enabled = false;

        Button1.Enabled = false;
    }

This is what I've done till now, but I cannot open the received PDF file - it says the file might be damaged. Please help me

protected void Button1_Click(object sender, EventArgs e)
    {
        SmtpClient smtpClient = new SmtpClient();
        MailMessage message = new MailMessage();


         MemoryStream mstream = new MemoryStream();
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        PdfWriter writer = PdfWriter.GetInstance(document, mstream);




        message.To.Add("admin@domain.com");
        if (CheckBox1.Checked == true)
        {
            emailadd.Text = employeenameDropDown.SelectedValue;

            message.Bcc.Add(emailadd.Text);

        }
        message.Subject = "Timesheet " + employeenameDropDown.SelectedItem;
        message.IsBodyHtml = true;
        message.Body = "<h3>Timesheet</h3>" + System.Environment.NewLine + System.Environment.NewLine + "<br/>";
        message.Body += "<b>Name: </b>" + employeenameDropDown.SelectedItem + "<br/>" + "<br/>";


        document.Open();
        document.Add(new Paragraph(message.Body));
        message.Attachments.Add(new Attachment(mstream, "time.pdf"));



        smtpClient.EnableSsl = true;
        smtpClient.Send(message);



        document.Close();
        mstream.Flush();
        mstream.Close();



        EmailSentForm.Visible = Visible;
        employeenameDropDown.Enabled = false;

        Button1.Enabled = false;
    }

Also, what to do if I want landscape layout of the PDF ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.