Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP.Net and Word 2007 templates

Status
Not open for further replies.

subgoat

Programmer
Sep 23, 2005
39
0
0
GB
Hi, I want to upgrade an existing ASP.Net application that generates Word douments on the server and streams them down to the client. I wna tto move to Word 2007 where the webserver apparently no longer requires that a user is logged on as Word 2007 can operate as a service.... The problem is I can't seem to find anything on the web about how to do this. So, what references do I need in the project to Word 2007 (i.e. version 12) and what's the best way of setting up bookmarks or referenceable objects in the document to be replaced by text from my application? Any pointer very much appreciated.
Regards, SubGoat
 
have you tried these links? you may need to dig up an SDK on word 2007 (not sure if one exists). searching for VS05 ms office might also help.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thanks for that. I have had a good look around, and it's quite difficult to get hold of any examples that really work. There is a potentially useful sample at as it tries to list bookmarks in a Word 2007 (xml-based) document. Frustratingly enough, it doesn't actually pick out the bookmarks in example files - even though I can see them within the XML itself. It does pull out 3 bookmarks from the sample that comes with the source download, but not from other docx files, so without being up-to-speed on the technicalities, this falls short of what I need. Has anyone out there looked at this? I'm simply wanting to complete bookedmarked fields in the Word 2007 document with known text from variables in my ASP.Net app. The crux of the problem seems to be the SelectNodes method of the XmlDocument, which should return the nodes list (when looking for "w:bookmarkStart") but doesn't. Ideally I want to be able to locate specific bookmark nodes within the collection and simply replace the text within that bookmark. Any ideas or pointers would be massively appreciated!
 
since it's an xml document load the file into an XmlDocument and create a simple XPathQuery to find the node(s) then loop through and replace the text. then save the file.

this would be a better approach, because MS Office/Word would not be required on the server.

Since this is an xml document, don't be concerned that it's a specific type of xml document (word 2007). only that it's a text document with tagged meta data.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thanks for this. I took your advice and reworked the bookmark XML tags via XPath queries, and got it to work. Then I since replaced all the bookmarks with content controls as I understand this is a better way of binding data to content in the new Word format, and it also allows creation of new table rows to be binded when you need dynamic table content generation. So, that's all great and working, and in my dev environment the response.writefile sends the content nicely to the browser and after clicking Open on the resulting 'File Download - Security Warning' dialog box, it automatically opens up word 2007 and displays just fine. Great! BUT when I come to put the app on a new web server (with Word 2007 installed so I can check it's working) the response.writefile produces the file dialog that doesn't have the Open button option. Instead of the right name of the file to be shown it shows the name of the aspx page from where it is sent, and the Type says 'Unknown File Type'. The only options are to Save or Cancel. Saving does indeed store a valid Word 2007 file.
I thought the problem must be the content type setting of the response object (which was "application/vnd.ms-word.document.12"), so I checked the setting in the registry to handle .docx files (in: HKEY_CLASSES_ROOT\MIME\Database\Content Type\ it has:

application/vnd.openxmlformats-officedocument.wordprocessingml.document

So I set this up, and in my dev environment again it works fine, but on the web server again I get the same problem. Maybe it's not the contentType setting? Any ideas on how to resolve this problem?

Thanks, SubGoat
 
Hi there, I sorted this out and in case anyone's interested, here's what the problem was: in the Response.AddHeader line, the file name I was downloading contained the full path to the file. Setting this to just the filename without any path info resolved it, and my missing Open button has not magically returned. Bingo!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top