다음을 통해 공유


ServerDocument 생성자 (Stream, String)

로드할 문서를 나타내는 스트림과 해당 문서의 파일 확장명을 사용하여 ServerDocument 클래스의 새 인스턴스를 초기화합니다.

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

구문

‘선언
Public Sub New ( _
    stream As Stream, _
    fileType As String _
)
public ServerDocument(
    Stream stream,
    string fileType
)

매개 변수

  • stream
    형식: System.IO.Stream
    로드할 문서를 나타내는 스트림입니다.
  • fileType
    형식: System.String
    bytes 매개 변수에 저장되는 문서의 파일 확장명은 마침표(.) 뒤에 옵니다(예: ".xlsx" 또는 ".docx").

예외

예외 상황
ArgumentNullException

stream 매개 변수가 nullNull 참조(Visual Basic의 경우 Nothing)이거나 비어 있는 경우

또는

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

ArgumentException

stream 매개 변수의 길이가 0이거나 현재 위치가 스트림의 끝에 있는 경우

UnknownCustomizationFileException

fileType 매개 변수로 지정된 파일 확장명이 Microsoft Visual Studio Tools for Office Runtime에서 지원되지 않는 경우

DocumentCustomizedWithPreviousRuntimeException

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

설명

이 생성자를 사용하여 메모리에 이미 있는 문서의 캐시된 데이터 또는 배포 매니페스트 정보에 액세스할 수 있습니다. 이 생성자를 사용하면 문서가 읽기/쓰기 권한으로 열립니다.

fileType 매개 변수는 바이트 배열에 저장되는 문서의 형식을 결정하는 데만 사용됩니다. fileType의 값은 문서 수준 사용자 지정에 대해 지원되는 파일 형식 중 하나에 매핑됩니다. 파일 열기를 시도하지 않았습니다. 선택적으로 전체 파일 이름(예: "Workbook1.xlsx")을 전달할 수 있지만 이 경우 파일 확장명만 사용됩니다. 지원되는 파일 형식에 대한 자세한 내용은 문서 수준 사용자 지정 아키텍처를 참조하십시오.

이 생성자를 호출한 후 문서의 바이트 배열에 액세스하려면 Document 속성을 사용합니다.

예제

다음 코드 예제에서는 ServerDocument(Stream, String) 생성자를 사용하여 파일 확장명이 .xlsx인 Excel 통합 문서가 포함된 FileStream에서 새 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 CreateServerDocumentFromStream(ByVal documentPath As String)
    Dim runtimeVersion As Integer = 0
    Dim serverDocument1 As ServerDocument = Nothing
    Dim stream As System.IO.FileStream = Nothing

    Try
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath)
        If runtimeVersion = 3 Then
            stream = New System.IO.FileStream(documentPath, System.IO.FileMode.Open)
            serverDocument1 = New ServerDocument(stream, "*.xlsx")
            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 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
        If Not (stream Is Nothing) Then
            stream.Close()
        End If
    End Try
End Sub
private void CreateServerDocumentFromStream(string documentPath)
{
    int runtimeVersion = 0;
    ServerDocument serverDocument1 = null;
    System.IO.FileStream stream = null;

    try
    {
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath);
        if (runtimeVersion == 3)
        {
            stream = new System.IO.FileStream(
                documentPath, System.IO.FileMode.Open);
            serverDocument1 = new ServerDocument(stream,
                "*.xlsx");
            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 (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();
        if (stream != null)
            stream.Close();
    }
}

.NET Framework 보안

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

참고 항목

참조

ServerDocument 클래스

ServerDocument 오버로드

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