다음을 통해 공유


ServerDocument 생성자 (String, FileAccess)

로드할 문서의 전체 경로와 해당 문서에 대한 파일 액세스를 나타내는 값을 사용하여 ServerDocument 클래스의 새 인스턴스를 초기화합니다.

네임스페이스:  Microsoft.VisualStudio.Tools.Applications
어셈블리:  Microsoft.VisualStudio.Tools.Applications.ServerDocument(Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll)

구문

‘선언
Public Sub New ( _
    documentPath As String, _
    access As FileAccess _
)
public ServerDocument(
    string documentPath,
    FileAccess access
)

매개 변수

  • documentPath
    형식: System.String
    로드할 문서의 전체 경로입니다.
  • access
    형식: System.IO.FileAccess
    문서에 대한 파일 액세스를 나타내는 값입니다.

예외

예외 상황
ArgumentNullException

documentPath 매개 변수가 nullNull 참조(Visual Basic의 경우 Nothing)이거나, 비어 있거나, 모두 공백 문자로 이루어져 있는 경우

ArgumentException

access의 값이 System.IO.FileAccess.Write인 경우

FileNotFoundException

documentPath에 지정된 파일이 없는 경우

DocumentNotCustomizedException

documentPath 매개 변수로 지정된 파일에 사용자 지정이 없고 access 값이 System.IO.FileAccess.Read인 경우

DocumentCustomizedWithPreviousRuntimeException

documentPath로 지정된 파일이 Visual Studio 2010 Tools for Office Runtime 또는 Microsoft Office 시스템(버전 3.0 런타임)용 Visual Studio 도구를 사용하여 만들지 않은 사용자 지정이 있습니다.

UnknownCustomizationFileException

documentPath로 지정된 파일의 파일 확장명이 Microsoft Visual Studio Tools for Office Runtime에서 지원되지 않는 경우

설명

문서를 읽기 전용 또는 쓰기 전용 권한으로 열려는 경우 이 생성자를 사용하여 디스크에 있는 문서의 캐시된 데이터 또는 배포 매니페스트 정보에 액세스할 수 있습니다. 기본적으로 다른 ServerDocument 생성자를 사용하면 문서는 읽기/쓰기 권한으로 열립니다.

예제

다음 코드 예제에서는 ServerDocument(String, FileAccess) 생성자를 사용하여 지정된 문서를 읽기 전용 권한으로 로드하는 새 ServerDocument를 만듭니다. 그런 다음 문서와 연결된 사용자 지정의 배포 매니페스트 URL을 표시합니다.

이 예제에는 다음 사항이 필요합니다.

  • 콘솔 응용 프로그램 프로젝트 또는 다른 비 Office 프로젝트입니다.

  • 다음 어셈블리에 대한 참조:

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll 및 Microsoft.VisualStudio.Tools.Applications.Runtime.dll(.NET Framework 4를 대상으로 하는 프로젝트의 경우)

      또는

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll 및 Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll(.NET Framework 3.5를 대상으로 하는 프로젝트의 경우)

  • 코드 파일 상단에 있는 Microsoft.VisualStudio.Tools.ApplicationsMicrosoft.VisualStudio.Tools.Applications.Runtime 네임스페이스에 대해 Imports(Visual Basic의 경우) 또는 using(C#의 경우) 문.

Private Sub CreateServerDocumentReadOnly(ByVal documentPath As String)
    Dim runtimeVersion As Integer = 0
    Dim serverDocument1 As ServerDocument = Nothing

    Try
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath)
        If runtimeVersion = 3 Then
            serverDocument1 = New ServerDocument(documentPath, System.IO.FileAccess.Read)
            MessageBox.Show("The URL of the deployment manifest is: " & vbLf & _
                serverDocument1.DeploymentManifestUrl.ToString())
        End If

    Catch ex As System.IO.FileNotFoundException
        System.Windows.Forms.MessageBox.Show("The specified document does not exist.")
    Catch ex As DocumentNotCustomizedException
        System.Windows.Forms.MessageBox.Show("The specified document does not " & _
            "have a customization.")
    Catch ex As UnknownCustomizationFileException
        System.Windows.Forms.MessageBox.Show("The specified document has a file " & _
            "extension that is not supported by Visual Studio Tools for Office.")
    Finally
        If Not (serverDocument1 Is Nothing) Then
            serverDocument1.Close()
        End If
    End Try
End Sub
private void CreateServerDocumentReadOnly(string documentPath)
{
    int runtimeVersion = 0;
    ServerDocument serverDocument1 = null;

    try
    {
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath);
        if (runtimeVersion == 3)
        {
            serverDocument1 = new ServerDocument(documentPath,
                System.IO.FileAccess.Read);
            MessageBox.Show("The URL of the deployment manifest is: \n" +
                serverDocument1.DeploymentManifestUrl.ToString());
        }
    }
    catch (System.IO.FileNotFoundException)
    {
        System.Windows.Forms.MessageBox.Show("The specified document does not exist.");
    }
    catch (DocumentNotCustomizedException)
    {
        System.Windows.Forms.MessageBox.Show("The specified document does not " +
            "have a customization.");
    }
    catch (UnknownCustomizationFileException)
    {
        System.Windows.Forms.MessageBox.Show("The specified document has a file " +
            "extension that is not supported by Visual Studio Tools for Office.");
    }
    finally
    {
        if (serverDocument1 != null)
            serverDocument1.Close();
    }
}

.NET Framework 보안

  • 직접 실행 호출자의 경우 완전히 신뢰합니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분 신뢰 코드에서 라이브러리 사용을 참조하십시오.

참고 항목

참조

ServerDocument 클래스

ServerDocument 오버로드

Microsoft.VisualStudio.Tools.Applications 네임스페이스