VSTO 2005 questions...

I hope that someone can help me with any of the following questions:

· Is it possible to run a VSTO 2005 application inside a Word 2003 document opened directly from a web (on a URL like http://server/app/mydocument.doc) (If so, how to configure the .NET 2.0 security on the client )

· Is it possible to run a VSTO 2005 application inside Word Viewer 2003

· How to highlight parts (words or periods) of a Word 2003 document by using VSTO 2005 and without modifying the document For example, my VSTO 2005 application needs to highlight somehow the phrase starting from the char at the position X and ending on the position X + Y. How this can be done I imagine that I can assign a SmartTag to that phrase; unfortunately with a SmartTag, the section is not highlighted in a very visible way; can I obtain something more visible (like the real Word “highlight tool”), but without modifying the document



Answer this question

VSTO 2005 questions...

  • Sangeetha_AS

    It is possible to run a VSTO 2005 application opened directly from a web. You'll need to create a code policy using the .NET configuration tool or caspol.exe.

    For example, using the caspol command line tool, you'd need something similar to (there are several different approaches you could take depending on how draconian and/or paranoid you are so use at your own risk ):

    cmd /c "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\caspol.exe -q -en -ag 1 -url "http://server/app/*" FullTrust -name "YourAppPolicyName" -levelfinal on -description "Policy to allow document customizations to run""

    You'll also need to publish the document to the desired site and you may need to tweak the application manifest. I've found the Application Manifest Editor tool to be useful for troubleshooting deployments like this - it's at: http://msdn2.microsoft.com/en-us/library/ms268756(VS.80).aspx.

    For a much more comprehensive understanding than I can possibly provide here, I'd recommend checking out chapters 19 &20 of Visual Studio Tools for Office by Eric Carter & Eric Lippert.

    Regards,

    Steve



  • THaines

    Hi Stefan

    I can't answer (1).

    (2) No, a VSTO solution can't run in the Word Viewer. The Word viewer is for reading, only. As a matter of fact, a VSTO solution won't work in all versions of Word that are sold, either. Search this group for a recent thread on "pre-requisites" and you'll find a link to a page listing which Office versions support VSTO

    (3) The only way, really, would be to select them. But I doubt this would do the job for you... However, once your code does the highlighting, you can set the .SAVED property of the document to True. This should suppress Word prompting the user to save changes when the document is closed.



  • agbeko


    Hi Stefan.

    In regards to (3), I don't believe there's a way to do the highlighting of portions of the document without at least _temporarily_ changing the document. In short, doing highlighting changes the document formatting.

    Macro
    With some input from one of my colleagues, I tried to record a macro to automate the Find dialog box (that provides the capability to highlight words) but I couldn't get it to do what I wanted. The steps I took in recording the macro highlighted the values in my document as I wanted but when I played it back it didn't have any apparent effect. I tried to modify it a bit but couldn't get it to do any actual highlighting so there may be a way to use a macro (if macros are a possible solution for you).

    Code
    I came up with some code that would move you in the right direction but not without some caveats. Consider the following code:

    (This sample assumes that the document contains words in which "WordToFind" is the text to highlight.)


    private void ThisDocument_Startup(object sender, System.EventArgs e)
    {
    foreach (Word.Range word in this.Words)
    {
    //If we trim, we need to highlight less than the size of the word otherwise the space after
    //the word is highlighted as well.
    if (string.Compare(word.Text.Trim(), "WordToFind", false, CultureInfo.InvariantCulture) == 0)
    {
    word.HighlightColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdBrightGreen;
    }
    }

    }


    private void ThisDocument_BeforeSave(object sender, Microsoft.Office.Tools.Word.SaveEventArgs e)
    {
    foreach (Word.Range word in this.Words)
    {
    //If we trim, we need to highlight less than the size of the word otherwise the space after
    //the word is highlighted as well.
    if (string.Compare(word.Text.Trim(), "WordToFind", false, CultureInfo.InvariantCulture) == 0)
    {
    word.HighlightColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdNoHighlight;
    }
    }
    }

    Basically, when the document opens you move through each word looking for the words to highlight and you highlight them. Before the user saves, you un-highlight them. A couple of issues come up almost immediately, however. If your document is large (contains a lot of words), moving through each word one at a time and comparing it to a list of words you want to hightlight will definitely take some time (I presume you're looking to highlight more than one particular word in a document). There are ways to do things like controls Word's screen updating behavior which may help (e.g, turn off updating, highlight the values, turn updating on). There may even be a way to write some code to only highlight the items on the current page (the page that is currently visible). Admittedly, I don't know if it's possible to determine what page is currently visible however.

    Then there's the problem of what happens when the user saves the document after you've highlighted some words With the code above, you'll unhighlight them and then the save will occur. However, now the user wants to continue using the document. :-( If you could write some logic to detect this situation, then you'd simply be toggling your highlighting on-and-off.

    Cindy mentions using the .Saved property. When I was writing up this code I used that property but then thought about the scenario when a user makes changes to the document after the .Saved property is set. The user will be prompted and a save could occur (of course, _BeforeSave would get called allowing you to undo your changes). So it might not be all that bad.

    With this sort of strategy, it sounds like there's a solution in here somewhere but it would require some work. Again, though, doing highlighting will modify the format of the document. What you would need to do is figure out how to keep those highlights from being persisted with the document.

    Hopefully this input helped a little.


  • VSTO 2005 questions...