[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 320
  • Last Modified:

Export Webform Results to Word Document

In the past I've created ASP.Net Web forms where the submitted info is sent to a SQL table and email notifications, with the same info, are sent to the requestor, and the people that need to complete the requests.

I need take that same info and save it to a specified location as a word doc. Below is the code to send out email. The existing text would be implemented on the word doc so they would have a uniform appearance.

Public Sub Send_Email()
        Dim Mail As New MailMessage()
        Dim mailBody As String

        Mail.From = New MailAddress("sender@domain.com")
        Mail.To.Add(strUser & "@domain.com")
        Mail.Subject = "Important Request"
        mailBody = "The following information has been submitted for an Important Request:" & "<br/>" & "<br/>"
        mailBody &= "<b>Server Name:  </b>" & TextBox1.Text & "<br/>"
        mailBody &= "<b>Server OS:  </b>" & DropDownList2.Text & "<br/>"
        mailBody &= "<b>Windows License? :  </b>" & DropDownList1.Text & "<br/>"
        mailBody &= "<b>Patch Window:  </b>" & TextBox3.Text & "<br/>"
        mailBody &= "<b>Administrator:  </b>" & TextBox4.Text & "<br/>"
        mailBody &= "<b>IIS Needed:  </b>" & DropDownList5.Text & "<br/>"
        mailBody &= "<b>Amount of Disk Space:  </b>" & TextBox6.Text & "<br/>"
        mailBody &= "<b>Disk Layout:  </b>" & TextBox7.Text & "<br/>"
        mailBody &= "<b>Memory (RAM):  </b>" & TextBox8.Text & "<br/>"
        mailBody &= "<b>Primary Application:  </b>" & TextBox9.Text & "<br/>"
        mailBody &= "<b>Database Connected:  </b>" & DropDownList10.Text & "<br/>"
        mailBody &= "<b>Requesting Department: </b>" & TextBox14.Text & "<br/>"
        mailBody &= "<b>Contact Person: </b>" & TextBox11.Text & "<br/>"
        mailBody &= "<b>Contact Phone:  </b>" & TextBox12.Text & "<br/>"
        mailBody &= "<b>SAN Space Purchased:  </b>" & DropDownList13.Text & "<br/>"
        mailBody &= "<b>Date Submitted:  </b>" & strDate & "<br/>"
        mailBody &= "<b>Requestor:  </b>" & strUser & "<br/>"

        Mail.Body = mailBody
        Mail.Priority = MailPriority.High ' Normal, Low or High
        Mail.IsBodyHtml = True

        Dim smtp As New SmtpClient("mail.domain")
        Catch ex As Exception
            MsgBox(Err.Description & vbCrLf & ex.ToString)
            Exit Sub
        End Try
    End Sub

Open in new window

1 Solution
This might help you: http://www.codeproject.com/KB/aspnet/wordapplication.aspx

One thing to note, in order for this to work office must be installed on the server the site is running on.
It is not recommended to have Office installed on the server. Use a 3rd party tool such as this which does not require office


Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now