방법: ServerDocument 클래스의 두 버전을 모두 사용하는 코드 작성

업데이트: 2007년 11월

적용 대상

이 항목의 정보는 지정된 Visual Studio Tools for Office 프로젝트 및 Microsoft Office 버전에만 적용됩니다.

프로젝트 형식

  • 문서 수준 프로젝트

Microsoft Office 버전

  • 2007 Microsoft Office system

  • Microsoft Office 2003

자세한 내용은 응용 프로그램 및 프로젝트 형식에 따라 사용 가능한 기능을 참조하십시오.

ServerDocument 클래스를 사용하여 Microsoft Office 2003 및 2007 Microsoft Office system의 사용자 지정을 관리하는 하나의 코드 파일을 만들 수 있습니다. 이렇게 하면 여러 버전의 Microsoft Office에 대한 사용자 지정을 관리해야 하는 경우 다시 사용할 수 있는 코드가 들어 있는 어셈블리를 만들 수 있습니다.

두 가지 버전의 ServerDocument 클래스의 차이점에 대한 자세한 내용은 ServerDocument 클래스를 사용하여 서버의 문서 관리를 참조하십시오.

ServerDocument 클래스의 두 버전을 모두 사용하는 코드를 작성하려면

  1. 다음 어셈블리에 대한 참조를 추가합니다.

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll

    • Microsoft.VisualStudio.Tools.Applications.Runtime.dll

  2. 코드 파일의 맨 위에 다음 using(Visual C#의 경우) 또는 Imports(Visual Basic의 경우) 문을 추가합니다. 이러한 문은 각 버전의 ServerDocument 클래스에 대한 네임스페이스 별칭을 정의합니다.

    Imports v3Runtime = Microsoft.VisualStudio.Tools.Applications
    Imports SERuntime = Microsoft.VisualStudio.Tools.Applications.Runtime
    
    using v3Runtime = Microsoft.VisualStudio.Tools.Applications;
    using SERuntime = Microsoft.VisualStudio.Tools.Applications.Runtime;
    
  3. GetCustomizationVersion 메서드를 사용하여 사용자 지정을 만드는 데 사용된 Visual Studio Tools for Office 런타임 버전을 확인합니다. 그런 다음 해당 런타임 버전의 ServerDocument 클래스를 사용하여 사용자 지정과 관련된 작업을 수행합니다.

    다음 코드 예제에서는 지정한 문서와 연결된 사용자 지정을 검사합니다. 해당 문서가 Microsoft Visual Studio Tools for the Microsoft Office system (버전 3.0 런타임), 즉 Word 2007용 프로젝트를 사용하여 사용자 지정된 경우 이 예제에서는 배포 매니페스트의 URL을 표시합니다. 해당 문서가 Visual Studio 2005 Tools for Office Second Edition 런타임, 즉 Word 2003용 프로젝트를 사용하여 사용자 지정된 경우 이 예제에서는 포함된 응용 프로그램 매니페스트의 내용을 표시합니다.

    Private Sub DisplayCustomizationInformation(ByVal documentPath As String)
        Dim runtimeVersion As Integer = 0
        Dim serverDocumentv3 As v3Runtime.ServerDocument = Nothing
        Dim serverDocumentSE As SERuntime.ServerDocument = Nothing
    
        Try
            runtimeVersion = v3Runtime.ServerDocument.GetCustomizationVersion(documentPath)
    
            ' Access a member that is specific to each version of the runtime.
            If runtimeVersion = 3 Then
                serverDocumentv3 = New v3Runtime.ServerDocument(documentPath)
                MessageBox.Show("The URL of the deployment manifest is: " & vbLf & _
                    serverDocumentv3.DeploymentManifestUrl.ToString())
            ElseIf runtimeVersion = 2 Then
                serverDocumentSE = New SERuntime.ServerDocument(documentPath)
                MessageBox.Show("The embedded application manifest has the following contents: " & vbLf _
                    & serverDocumentSE.AppManifest.ToXml())
            End If
    
        Catch ex As System.IO.FileNotFoundException
            System.Windows.Forms.MessageBox.Show("The specified document does not exist.")
        Finally
            If Not (serverDocumentv3 Is Nothing) Then
                serverDocumentv3.Close()
            End If
            If Not (serverDocumentSE Is Nothing) Then
                serverDocumentSE.Close()
            End If
        End Try
    End Sub
    
    private void DisplayCustomizationInformation(string documentPath)
    {
        int runtimeVersion = 0;
        v3Runtime.ServerDocument serverDocumentv3 = null;
        SERuntime.ServerDocument serverDocumentSE = null;
    
        try
        {
            runtimeVersion = v3Runtime.ServerDocument.GetCustomizationVersion(documentPath);
    
            // Access a member that is specific to each version of the runtime.
            if (runtimeVersion == 3)
            {
                serverDocumentv3 = new v3Runtime.ServerDocument(documentPath);
                MessageBox.Show("The URL of the deployment manifest is: \n" +
                    serverDocumentv3.DeploymentManifestUrl.ToString());
            }
            else if (runtimeVersion == 2)
            {
                serverDocumentSE = new SERuntime.ServerDocument(documentPath);
                MessageBox.Show("The embedded application manifest has the following contents: \n" +
                    serverDocumentSE.AppManifest.ToXml());
            }
        }
        catch (System.IO.FileNotFoundException)
        {
            System.Windows.Forms.MessageBox.Show("The specified document does not exist.");
        }
        finally
        {
            if (serverDocumentv3 != null)
                serverDocumentv3.Close();
            if (serverDocumentSE != null)
                serverDocumentSE.Close();
        }
    }
    

참고 항목

개념

ServerDocument 클래스를 사용하여 서버의 문서 관리

참조

Microsoft.VisualStudio.Tools.Applications.ServerDocument

Microsoft.VisualStudio.Tools.Applications.Runtime.ServerDocument