Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Com DLL's and Web Parts

  Asked By: Coty    Date: Apr 29    Category: Sharepoint    Views: 4221

I am trying to use the MS Word COM DLL in a web part to enable creation
of Word Docs on the fly while within sharepoint. I cannot get the code
that works fine outside of Sharepoint to work in the web part. Is it a
Interop thing? Would this apply to all COM DLL's?



9 Answers Found

Answer #1    Answered By: Irvin Foley     Answered On: Apr 29

Is word  installed on the server?

I wouldn’t try to generate the word doc on the server since it’s not scalable.

Worst case, If I needed to create the documents on the server, I’d create RTF documents that Word can read.

Alternatively, you might bring down a simple Word Template with the code necessary to figure out how to fill itself out.

Answer #2    Answered By: Deonte Stein     Answered On: Apr 29

Actually, what I need to do is gather data using a custom list, then use that data to populate a Word document that can be auto filled in and then added to a linked doc library? It has small number of users so Im not worried about scalability. Is that scenario doable?

Answer #3    Answered By: Stephon Valentine     Answered On: Apr 29

Word doesn’t like SharePoint lists very much… You can use this work  around … thorprojects.com/blog/archive/2005/08/06/179.aspx

Answer #4    Answered By: Leif Cardenas     Answered On: Apr 29

Since I am only producing one letter at a time, the solution I came up with includes using the Sharepoint Object Model to access the list data. I retrieve the correct list item and walk thru the instance of SPListItem which contains the actual data. When I have the architecture nailed down a little more, I plan on posting it, since I think it is a viable solution for some situations.

Answer #5    Answered By: Jasper Hatfield     Answered On: Apr 29

I understand that there are some times when it is expedient to produce Word documents on the server and bring them down. However, the Office applications are primarily single threaded. They are designed for one user to access – they aren’t designed to be used in server processes. More recent versions have gotten much better about this, however, in general they’re not recommended for server processes. The challenge is that you end up blocking on the Word API so your server seems to slow down when you have many people doing creation operations at the same time. Really, all I’m doing is exposing a potential scalability issue with your mechanism. If it’s low volume it won’t matter.

Answer #6    Answered By: Rashawn Hopper     Answered On: Apr 29

I really do appreciate your opinion. I didn't mean to sound like a know-it-all by any means. I particpate in this group because I respect other people's ideas and opinions. I know I will have potential issues calling multiple instances of WinWord.exe on the server. However, in this particular situation, we are willing to deal with those cons in order to gain the quick hit functionality we are looking for. We anticipate no more than 5-10 users at any given time executing the Word creation feature.

I am willing to research other avenues, but since this is a very low-bid job, we only have so many resources to apply  to that research. AFAIK, the idea of using RTF involves a lot of custom parsing to create the right markup for the RTF specification. Any other ideas are certainly welcome.

BTW, I am also planning on writing a system utility to monitor the instances of WinWord running on the server and auto-kill any that are older than a certain date.

Answer #7    Answered By: Horace Coffey     Answered On: Apr 29

Excel Server is coming in Office 12 and will address just this kind of
issue. I've not heard of "Word Server" to replace Word automation but if
I could make a case to the product team...

Answer #8    Answered By: Rigoberto Beard     Answered On: Apr 29

May I suggest looking at Visual Studio Tools for Office, version 2005? (VSTO) Here's a link to a webcast that explains how to create documents on the server without having to install the office applications on the server by using the new ServerDocument Class.


Currently, developers program against Office documents on the server by creating instances of the Office application and manipulating the document via the appropriate Office DOM. One of the key enhancements in Visual Studio Tools for Office 2005 is the new and powerful ServerDocument class, which grants the ability to work  with the data on the server from within a document without having to understand the view constructs of the host application. This provides easier client side development, as well as improved performance and efficiency. In this webcast, we will explain and demonstrate how you can take advantage of the VSTO ServerDocument capabilities in your applications.

There's also a whitepaper on MSDN on this topic here:
Overview of Server Capabilities in Visual Studio 2005 Tools for Office

Answer #9    Answered By: Alphonso Mckay     Answered On: Apr 29

If the users are on Office 2003, the easiest approach is to create
the word  document in XML format. This is the replacement for RTF,
and is much easier to program to. You can use a simple XSLT
transform to create documents from data.

If you look at a document in XML format created by Word, it looks
scary and complex. But if you create one yourself, you can omit a
lot of stuff (eg unused style definitions) and keep it simple.

Another approach is to use an existing Word XML doc as a shell and
simply write in your data to xpath nodes. An easy technique is to
create the doc with the data as custom properties, then use Word
fields to include the data within the doc. You can then update the
data by using the xpath to the custom properties, and the layout of
the document is completely independent of your code.

Here is an example where some data is placed in a custom property. A
word field code makes the data appear as a heading.

Your xml data:

<?xml version="1.0" encoding="UTF-8"?>
<information>My info</information>

An xslt transform for a valid Word doc:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
<xsl:output method="xml" version="1.0" encoding="UTF-8"
<xsl:template match="/">
<xsl:variable name="myinfo" select="information"/>
<xsl:text disable-output-escaping="yes"> </xsl:text>
<xsl:text disable-output-escaping="yes"><?mso-application
<xsl:text disable-output-escaping="yes"> </xsl:text>
<o:InfoFromXML dt:dt="string">
<xsl:value-of select="$myinfo"/>
<w:style w:type="paragraph" w:styleId="Heading1">
<w:name w:val="heading 1"/>
<wx:uiName wx:val="Heading 1"/>
<w:pStyle w:val="Heading1"/>
<w:outlineLvl w:val="0"/>
<wx:font wx:val="Times New Roman"/>
<w:i w:val="off"/>
<w:pStyle w:val="Heading1"/>
<w:fldChar w:fldCharType="begin"/>
<w:instrText> DOCPROPERTY InfoFromXML
<w:fldChar w:fldCharType="separate"/>
<w:t>Press F9 to update!!</w:t>
<w:fldChar w:fldCharType="end"/>

Didn't find what you were looking for? Find more on Com DLL's and Web Parts Or get search suggestion and latest updates.