ServerDocument Rules of the Road

Saturday, July 1, 2006 – 8:16 AM

Another question people ask me a lot is what the rules of the road are for using VSTO on the Server with the ServerDocument class. Typically because they’re trying to add a customization on a machine that doesn’t have Office installed using ServerDocument.AddCustomization. The problem is that AddCustomization behaves differently depending on whether the document has previously been customized and had a Runtime Storage Control (RSC) added to it. 

RSC Present No RSC
Office Installed In this case you can use the ServerDocument constructor onClient parameter to decide if you want to start Office or not. ServerDocument will start Word or Excel in order to add the RSC to the document. If you set onClient=false then it will error.
No Office ServerDocument can modify the customization using the existing RSC. Ooops! The document doesn’t have a RSC and there’s no way to add it. If you try this you’ll get a weird COM exception.

Usually when I’m asked about this it’s because the user is trying to add a VSTO customization to a new document on a (web) server where Office is not installed. The best approach in this scenario is to use a previously customized document and if need be create a copy of it, rather than trying to create a new one from scratch. 

So I  hear you cursing Microsoft for all this. I agree the COM exception isn’t the best – there should be a much better error there. However if you really think you want to start Office on the server then I’d suggest thinking long and hard about that one. Excel and Office are big applications and while VSTO doesn’t prevent you doing this its likely to really degrade your server performance.

You can read more about the Runtime Storage Control on MSDN, the ServerDocument reference is there also.

  1. 2 Responses to “ServerDocument Rules of the Road”

  2. Hi,

    I am using VSTO to put some data in excel workbook. My scenario is I can have nay excel workbook given by user in which they have created charts and I need to populate data to particular ranges.

    Now the problem is this Excel which user is giving is uncustomized excel and when i try to put read this excel using ServerDocument class it gives me error of manifest as this uncustomized document.

    Now if I try to add customization using AddCustomization method giving the document path I am getting the error of Access Denied.

    I dont know why this is happening.
    Any help in this reagrd..

    tarun

    By tarun on Nov 27, 2007

  3. Tarun,

    There’s not enough information here to try and figure out what’s going wrong. If I were to take a wild guess it would be that you’re trying to call AddCustomization from behind a ASP.NET page on the server and you actually do have Office installed. Two points. Firstly I’d advise against doing this (see above). Secondly if this is what you are doing then my best guess is that the AddCustomization method is executing under the ASP.NET service account and does not have permission to modify the document.

    Hope this helps.

    Ade

    By Ade on Dec 2, 2007

Sorry, comments for this entry are closed at this time.