Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
Hi All,

I am able to create a new word file with below code. Now, instead of writing all new code for data I want to insert the contents of an aspx page into it. Pls guide. i have searched the net but could not find any idea for this.

Thanks
Atul

VB
Dim wordApp As New Application()
        Dim filePath As Object = "H:\TestDocument.docx"
        Dim missing As Object = System.Reflection.Missing.Value

        Dim wordDoc As Document = wordApp.Documents.Add(missing, missing, missing, missing)

        wordDoc.Activate()
        wordDoc.Content.InsertBefore("This is Word document created in ASP.NET")
        wordDoc.Content.InsertParagraphAfter()
        wordDoc.SaveAs(filePath)
        wordApp.Application.Quit(missing, missing, missing)
Posted
Updated 28-Jun-15 2:27am
v2
Comments
Suvendu Shekhar Giri 28-Jun-15 8:59am    
Instead of using pysical drive path to save the word file, it would be good idea to save in the application path using Server.MapPath()
atul sharma 5126 29-Jun-15 1:29am    
I agree to your suggestion and I have same thing for final code. but for now my focus was to automatically save the whole page at a pre-decided location
Afzaal Ahmad Zeeshan 28-Jun-15 9:41am    
Instead of adding hard-coded text, you should be passing the variable data for the string and other similar HTML nodes. It would be a very much long process; in my opinion.
atul sharma 5126 29-Jun-15 1:30am    
Absolutely right. for this reason itself I want to save the already created aspx page as a whole.

1 solution

If you want to save whole aspx page then go through the below URL.
http://forums.asp.net/t/1204503.aspx[^]

Let me know if you need any help.
 
Share this answer
 
Comments
atul sharma 5126 29-Jun-15 1:16am    
Thanks for the reply dear.
I was able to save the whole page with following code but facing two issues:

1. It asks for whether I want to open or save the page when I would like the page to automatically be saved.
2. The page is saved in landscape format when it should be saved in potrait A4 ready to print format.
Pls suggest.

Thanks again..

Response.ClearHeaders()
Response.Clear()
'this clears the Response of any headers or previous output
Response.Buffer = True
'make sure that the entire output is rendered simultaneously
Response.ContentType = "application/msword"
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName + ".doc")

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900