Asp.Net >> HTML String to Word with Header and Footer (ASP.NET and VB.NET)

by sasikumar.gunasekaran » Tue, 01 Apr 2008 14:51:02 GMT

I have to create a MS - Word document with header and footer from a
HTML string. I am using the below code.

Dim strHTML As String = "<html><body><br><b>hello</b><br></body></
html>"
Response.Cache.SetExpires(DateTime.Now.AddSeconds(1))
Response.Clear()
Response.AppendHeader("content-disposition",
"attachment;filename=FileName.doc")
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "application/vnd.ms-word"
Me.EnableViewState = False
Response.Write("\r\n")
Response.Write(HttpUtility.HtmlDecode(strHTML))
Response.End()

I want to build the HTML with header and footer which will be later
converted into a MS Word with Header and Footer also if the pages got
increased.

Please help me out.

Similar Threads

1. HTML String to Word with Header and Footer (ASP.NET and VB.NET)

I have to create a MS - Word document with header and footer from a
HTML string. I am using the below code.

Dim strHTML As String = "<html><body><br><b>hello</b><br></body></
html>"
Response.Cache.SetExpires(DateTime.Now.AddSeconds(1))
Response.Clear()
Response.AppendHeader("content-disposition",
"attachment;filename=FileName.doc")
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "application/vnd.ms-word"
Me.EnableViewState = False
Response.Write("\r\n")
Response.Write(HttpUtility.HtmlDecode(strHTML))
Response.End()

I want to build the HTML with header and footer which will be later
converted into a MS Word with Header and Footer also if the pages got
increased.

Please help me out.

2. Opening word, excel, pp document under asp.net with VB.net code behind - Asp.Net

3. Help required in opening word document from ASP.NET(VB.NET) applic

Hi,

We are working on an ASP.NET (VB.NET) application and we have a problem 
opening a word 

document from our application. When we try to open the word document, we do 
not get any 

error message but the system hangs.

Our requirement is to open a word document on the server and write our 
content to it and 

save it on the server and then open the document through a link on the 
client machine.

Basically, all we need is the syntax/code sample to open a word document 
from our web 

application (ASP.NET/VB.NET). 

Thanks in advance
oursmp

4. Word Automation using ASP .NET and VB .NET

5. Chartspace for ASP.NET or VB.NET

6. Find Replace for Word in Header, Footer, Body (VB.NET) - Word VBA

7. Opening MS Word from a VB.NET ASP Page Access Denied

Hi,

Being fairly new to .NET I am looking for a way to call 
MS 
Word from an event on a webform, and after the user is 
finished save that created document to an SQL Server 
database.  Has anyone done this? Does it seem possible? I 
followed the instructions from a sample on the Microsoft 
knowledge base but it only seems to work when creating a 
VB.NET Windows .EXE, not an VB.NET ASP app.

        Imports Word=Microsoft.Office.Interop.Word

        Dim oWord As Word.Application
        Dim oDoc As Word.Document


        'Start Word and open the document template.
        oWord = CreateObject("Word.Application")
        oWord.Visible = True
        oDoc = oWord.Documents.Add

I changed the sample code to the following:

        Dim oWord As Word.ApplicationClass
        Dim oDoc As Word.DocumentClass


        'Start Word and open the document template.
        oWord = New Word.ApplicationClass()
        oWord.Visible = True
        oDoc = oWord.Documents.Add

But when i build the solution it gives me the following 
error:

Access Denied

Exception Details: System.UnauthorizedAccessException: 
Access is denied.

The ASP.NET process is not authorized to access the 
request. For security reasons the default ASP.NET process 
is '{machinename}\ASPNET' which has limited privileges.  
Consider granting access rights to the resource to the 
ASP.NET process identity.

Line 31:  oWord = New Word.ApplicationClass()

But it does not specify what it is trying to gain access 
to.  I tried giving the asp account admin rights just to 
test but that didnt work.  I also lowered to security 
settings on IE to test as well, and I gave the ASPNET 
account full access to the 
Microsoft.Office.Interop.Word.dll.

Any ideas?

Thanks.


8. Opening MS Word from a VB.NET ASP application - Asp.Net