HOWTO: Host Office Documents with VSTO automation inside SharePoint 2007 Document Library
It’s very easy to upload Word template to Microsoft Office SharePoint (MOSS) 2007 document library. However, it’s not that straight forward to setup and deploy Word template with VSTO code behind in MOSS 2007 document Library.
Following guidelines shows how to deploy such documents to a MOSS 2007 document library and make sure they work in as long as Users have access to Deployment Manifest.
Prerequisites for Clients
· The Microsoft .NET Framework version 2.0
· Microsoft Office 2003 applications that support VSTO 2005 document-based solutions
OR
Microsoft Office 2003 applications that support VSTO 2005 SE add-ins
· Primary Interop assemblies
A typical installation of Microsoft Office 2003 or a stand-alone product such as Word sets the applications to install the primary interop assemblies on first use of the product. A full installation installs the primary interop assemblies during the installation process.
If you do not know whether a specific computer has the Primary Interop Assemblies installed, you should install the primary interop assemblies as part of your solution.
· VSTO 2005 SE runtime
· Visual Studio Tools for Office Language Pack (optional)
Steps for Building and Deploying VSTO solution:
1. Create VSTO Project
Create VSTO project for the Document level add-in for Word 2003/2007 using Visual Studio Tools for Office 2005 SE. Add necessary code to successfully run the project.
2. Build and Publish the solution
Once successfully built and tested, publish the project.Using Visual Studio 2005 publishing wizard, publish the project to network file share or SharePoint share.
(Note: End user MUST have access to this location without getting prompted to Network Credentials. This is the location where Deployment Manifest and assemblies will be located.)
3. Grant full trust to the network folder
Before granting permission, first Add Msosec.dll to the global assembly cache (GAC). Msosec.dll is the assembly that implements Microsoft.Office.Security.Policy.OfficeDocumentMembershipCondition, which is used to identify documents and workbooks. You can find Msosec.dll in the ADDINS folder under your Office installation location, which by default is \Program Files\Microsoft Office\OFFICE11\ADDINS.
How to Add MSOSEC.DLL to the assembly cache:
GacUtil.exe is targeted for developers and therefore it’s not shipped as part of the .NET 2.0 framework. For production environment, MSDN documentation suggests to use Windows Installer.
Follow steps for creating Setup or Installer project in VS 2005.
1. Create [Setup] project using Visual Studio 2005
2. Right Click Project and Select View/File System.
3. Right Click [File System On Target Machine] and Add Special Folder [Global Assembly Cache Folder]
4. Select [Global Assembly Cache Folder] and then Right-Click and add [Assembly] and select C:\Program Files\Microsoft Office\Office11\ADDINS\MSOSEC.DLL
5. Build the solution and this will create SETUP.EXE and XXXX.MSI (XXXXX = [Name of the project]).
Grant full trust to the assemblies in each end user's security policy.
There are basically 2 automated ways to do this.
1) Create simple Batch file as follows:
Example:
Cd %systemroot%\Microsoft.NET\Framework\v2.0.50727
caspol -m -ag LocalIntranet_Zone -url \\ServerName\FolderName\* Nothing -n "My Data Folder" -d "Intermediate group for my documents"
caspol -m -ag "My Data Folder" -custom "C:\Program Files\Microsoft Office\Office11\Addins\Msosec.xml" FullTrust -n "My Data Documents" -d "Grants FullTrust to all documents in my data folder"
caspol -m -ag LocalIntranet_Zone -url \\DeployServer\ShareFolder\* FullTrust -n "Remote Deployment" -d "Deployment Walkthrough"
https://msdn2.microsoft.com/en-us/library/13wcxx6y(VS.80).aspx
OR
2) Create Deployment Package as follows:
· Basically, create a trust manually on the one of the computer using .NET Framework 2.0, start the SDK Command Prompt and type MSCORCFG.MSC
· In the left pane, right-click the Runtime Security Policy node.
· From the menu, choose Create Deployment Package.
https://msdn2.microsoft.com/en-us/library/13wcxx6y(VS.80).aspx
5. Upload the document template
Once all of the above steps are completed, upload the Word Template document to MOSS 2007 document library. That's It.
Good luck!
Comments
Anonymous
August 13, 2007
Hi Prashant, Thanks for sharing gr8 knowledge in blog. Its helped us a lot as its explaing step by step. I have just one confusion in my mind... what it means by "\ServerNameFolderName*" in Batch file? "ServerName" is it sharepoint server and if yes ? then which "FolderName" are you referring to. Thanks in advance. Thanks, Nilang ShahAnonymous
August 14, 2007
"\ServerName" is the one where your assemblies are located. It's not the Share Point server name.Anonymous
August 15, 2007
Hi Prashant Thanks for your quick reply. => then what is the difference between? "\ServerNameFolderName*" and "\DeployServerShareFolder*" (here where we publishing VSTO project) => then which server we need to put as "ServerName"? is this something diffent then "DeployServer"? => is there any advantage for following step in batch file?
caspol -m -ag LocalIntranet_Zone -url \ServerNameFolderName* Nothing -n "My Data Folder" -d "Intermediate group for my documents"
- Anonymous
October 09, 2007
The comment has been removed - Anonymous
February 12, 2008
if is possible to create Document level add-in for Word 2007 using Visual Studio Tools for Office 2005 SE by VS2005?