Link an assembly to a word or Excel File

Source: Internet
Author: User
How to: link an assembly to a word or Excel File

Microsoft Office 2003 documents containing managed code extensions must have paths to their associated assembly. The path and Assembly name are stored in the Custom Attributes of the document._ Assemblylocation0And_ Assemblyname0. The path must have one of the following formats:

  • Absolute path (C:\Assemblies\)
  • Relative Path (\Assemblies\)
  • HTTP (http://www.contoso.com/assemblies/)
  • UNC (\\AssemblyServer\Assemblies\)

For more information about valid paths, see the "assembly link location" attribute.

If the Assembly name or position is longer than 255 characters in length, more custom properties will be added to the Office document in order of numbers to include extra characters. For example, if the Assembly position contains 300 characters, two attributes are required:_ Assemblylocation0And_ Assemblylocation1.

Set the Assembly name and location in the word or Excel File

You can set the Assembly name and location in the Custom properties of the word or Excel file. There are three methods:

  • Use the "properties" window in Visual Studio. NET (recommended ).
  • Run the script for setting properties.
  • Manually set properties in the document, either in Windows resource manager or in the application itself.

Not all document formats support custom attributes. For example, if you save a document as a text file (.txt), the Assembly information is not saved.

Use the "properties" window in Visual Studio. NET to link an assembly to a file

  • Before creating a solution, set the "assembly link location" project property in the "properties" window to the Assembly location.

Using the Properties window in the Visual Studio. Net project helps to synchronize between the project and the deployed solution.

Use scripts to link an assembly to a file

Use the persistence control script to change_ Assemblylocation0Custom Attributes.

  1. Create a script to instantiate the control and call the desired method. For more information about methods, see the persistence control method.

    For example, use JScript:

    // JScript    if (WScript.Arguments.Length < 3)    {    print("Usage: SetAssemblyNameAndLocation <document> <assembly> <location>")    print("")    print("  <document> is the name of a Word document or Excel spreadsheet")    print("  <assembly> is the name of the assembly, without the extension")    print("  <location> can be a relative path, and should end in a slash")    WScript.Quit(1)    }    var doc = WScript.Arguments(0)    var asm = WScript.Arguments(1)    var loc = WScript.Arguments(2)    print("Updating '" + doc + "', setting assembly='" + asm + "' and location='" + loc + "'")    try    {    var control = new ActiveXObject("OfficeToolkit.Persistence")    control.SetAssemblyNameAndLocation(doc, asm, loc)    print("Success!")    }    catch(e)    {    print("Error:")    print(e.number + ": " + e.description)    WScript.Quit(2)    }    function print(s)    {    WScript.Echo(s)    }

    The following code uses VBScript to demonstrate the same example:

    ' VBScript    If (WScript.Arguments.Length < 3) Then    print "Usage: SetAssemblyNameAndLocation <document> <assembly> <location>"    print ""    print "  <document> is the name of a Word document or Excel spreadsheet"    print "  <assembly> is the name of the assembly, without the extension"    print "  <location> can be a relative path, and should end in a slash"    WScript.Quit 1    End If    Dim doc    Dim asm    Dim loc    doc = WScript.Arguments(0)    asm = WScript.Arguments(1)    loc = WScript.Arguments(2)    print "Updating '" & doc & "', setting assembly='" & asm & _    "' and location='" & loc & "'"    On Error Resume Next    Dim control    Set control = CreateObject("OfficeToolkit.Persistence")    control.SetAssemblyNameAndLocation doc, asm, loc    If (Err.Number <> 0) Then    print "Error:"    print Err.Number & ": " & Err.Description    WScript.Quit 2    End If    On Error Goto 0    print "Success!"    Sub print(s)    WScript.Echo s    End Sub
  2. Save the file with a specific name and add the extension. js (using JScript) or. vbs (Using VBScript) at the end of the file name ).
  3. Open command prompt.
  4. Change the directory to the location where the script file is saved.
  5. Type the name of the script file (without the extension), followed by three parameters (in the following order ):
    <script file> <document name> <assembly name> <deployment location>
  6. PressEnterKey.

This example script is invalid for encrypted workbooks or non-local file types (such as HTML or MHT. For more information, see "deploy encrypted Excel workbooks" in security deployment ".

Link the Assembly by Manually changing properties in word or Excel

  1. Open a document in word or Excel.
  2. Open the File menu and click Properties ".

    The "properties" dialog box of the document or workbook opens.

  3. Click the custom tab.
  4. In the "properties" list, select_ Assemblylocation0.

    Fill in the fields at the top of the dialog box with the data of this attribute.

  5. Add the path containing the Assembly directory to the "value" field.

    Note:Windows resource manager does not accept a value of more than 255 characters in the "value" Field of the "properties" dialog box.

  6. Select_ Assemblyname0.
  7. Add the Assembly name (without the file extension) to the value field.
  8. Click OK ".

Use Windows Resource Manager to manually change properties to link the Assembly

  1. Open windows Resource Manager, browse to a document or workbook, and select it.
  2. Open the File menu and click Properties ".

    The "properties" dialog box of the document or workbook opens.

  3. Click the custom tab.

    Custom document attributes are not displayed in the "properties" list on the "Custom" tab. However, you can manually enter a name and a value to change the property value.

    Note:If a document or workbook without Custom Attributes is opened, the "Custom" tab is not displayed in the "properties" dialog box of any document or workbook. If the "Custom" tab is not displayed in the "properties" dialog box, close all open documents or workbooks and restart the process.

  4. In the "name" field, Type_ Assemblylocation0.
  5. In the value field, type the path of the directory containing the assembly.

    Note:Windows resource manager does not accept a value of more than 255 characters in the "value" Field of the "properties" dialog box.

  6. In the "name" field, Type_ Assemblyname0.
  7. In the value field, type the Assembly name without the file extension ).
  8. Click OK ".

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.