Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5989287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:04:48+00:00 2026-05-22T23:04:48+00:00

I have a vb.net web app, and I need to give my users the

  • 0

I have a vb.net web app, and I need to give my users the facility to download a ms-word .doc file. This file needs to be created dynamically, and should contain some bold text and a table.

I’ve come across this code, which builds a .doc file, and lets you download it:

  Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim strFileName As String = "GenerateDocument" + ".doc"
        HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=" + strFileName)
        Dim strHTMLContent As StringBuilder = New StringBuilder()

        HttpContext.Current.Response.Clear()
        HttpContext.Current.Response.Charset = ""
        HttpContext.Current.Response.ContentType = "application/msword"

        strHTMLContent.Append("<p align='Center'>MY CONTENT GOES HERE</p>".ToString())

        HttpContext.Current.Response.Write(strHTMLContent)
        HttpContext.Current.Response.End()
        HttpContext.Current.Response.Flush()
  End Sub

…but I don’t know how to make the text bold, or create a table. I’m sure there’s a better way.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:04:49+00:00Added an answer on May 22, 2026 at 11:04 pm

    Sorry to answer my own question, but I’ve just come across this: http://www.codeproject.com/KB/office/Wordyna.aspx

    It works perfectly for me, because it allows HTML input. So tables are a doddle.

    Public Sub Page_Load(sender as Object, e as EventArgs)
    
        'build the content for the dynamic Word document
    
        'in HTML alongwith some Office specific style properties. 
    
        Dim strBody As New System.Text.StringBuilder("")
    
        strBody.Append("<html " & _ 
                "xmlns:o='urn:schemas-microsoft-com:office:office' " & _
                "xmlns:w='urn:schemas-microsoft-com:office:word'" & _ 
                "xmlns='http://www.w3.org/TR/REC-html40'>" & _
                "<head><title>Time</title>") 
    
        'The setting specifies document's view after it is downloaded as Print
    
        'instead of the default Web Layout
    
        strBody.Append("<!--[if gte mso 9]>" & _
                                 "<xml>" & _ 
                                 "<w:WordDocument>" & _
                                 "<w:View>Print</w:View>" & _
                                 "<w:Zoom>90</w:Zoom>" & _ 
                                 "<w:DoNotOptimizeForBrowser/>" & _
                                 "</w:WordDocument>" & _
                                 "</xml>" & _ 
                                 "<![endif]-->")
    
        strBody.Append("<style>" & _
                                "<!-- /* Style Definitions */" & _
                                "@page Section1" & _
                                "   {size:8.5in 11.0in; " & _
                                "   margin:1.0in 1.25in 1.0in 1.25in ; " & _
                                "   mso-header-margin:.5in; " & _
                                "   mso-footer-margin:.5in; mso-paper-source:0;}" & _
                                " div.Section1" & _
                                "   {page:Section1;}" & _
                                "-->" & _
                               "</style></head>") 
    
        strBody.Append("<body lang=EN-US style='tab-interval:.5in'>" & _
                                "<div class=Section1>" & _
                                "<h1>Time and tide wait for none</h1>" & _ 
                                "<p style='color:red'><I>" & _
                                DateTime.Now & "</I></p>" & _
                                "</div>" & _
                                "<div>" & _
                                "<table border=1>" & _
                                "<tr>" & _
                                "<td>1</td>" & _
                                "<td>2</td>" & _
                                "<td>3</td>" & _
                                "</tr>" & _
                                "<tr>" & _
                                "<td>a</td>" & _
                                "<td>b</td>" & _
                                "<td>c</td>" & _
                                "</tr>" & _
                                "</table>" & _
                                "</div>" & _
                                "</body></html>")
    
        'Force this content to be downloaded 
    
        'as a Word document with the name of your choice
    
        Response.AppendHeader("Content-Type", "application/msword")
        Response.AppendHeader ("Content-disposition", _
                               "attachment; filename=myword.doc")
        Response.Write(strBody)
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

need ask you about some help. I have web app running in Net 2.0.
I have this .NET web app that draws a table in Page_Load. Then after
I have an asp.net update web app. Users go the the page, hit the
Background I have a page on my ASP.NET MVC web app for users to
I have an ASP.NET MVC web app and have a function that I need
I have some configuration values for an asp.net web app. They will be maintained
In order to debug an asp.net web app I have to have IE Script
I have a SQL Server 2000, C# & ASP.net web app. We want to
I have an ASP.NET 2.0 web app and part of the structure still has
I am working on a web app using C# and asp.net I have been

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.