ServerDocument.Save 메서드

ServerDocument 클래스를 사용하여 문서의 변경 내용을 저장합니다.

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

구문

‘선언
Public Sub Save
public void Save()

예외

예외 조건
DocumentClosedException

ServerDocument이 닫힌 경우

MissingHostItemIdException

CachedDataHostItemId 속성이 nullNull 참조(Visual Basic의 경우 Nothing)이거나 비어 있는 경우

MissingDataIdException

CachedDataItemId 속성이 nullNull 참조(Visual Basic의 경우 Nothing)이거나 비어 있는 경우

MissingTypeException

CachedDataItemDataType 속성이 nullNull 참조(Visual Basic의 경우 Nothing)이거나 비어 있는 경우

설명

Save 메서드는 문서의 캐시된 데이터 또는 배포 매니페스트 URL에 대한 변경 내용을 저장합니다.디스크의 문서를 사용하여 ServerDocument 개체를 만든 경우 이 메서드는 이러한 변경 내용을 디스크에 저장합니다.메모리의 문서를 사용하여 ServerDocument 개체를 만든 경우 이 메서드는 해당 변경 내용을 메모리 버퍼에 저장합니다.

예제

다음 코드 예제에서는 지정된 Excel 통합 문서에 대한 새 ServerDocument를 만들고 SerializeDataInstance 메서드를 사용하여 워크시트에 캐시된 문자열의 값을 수정한 다음 Save 메서드를 사용하여 변경 내용을 저장합니다.

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

  • ExcelWorkbook1 네임스페이스에서 Sheet1 클래스가 있는 Excel의 문서 수준 사용자 지정 및 CachedString라는 Sheet1 클래스의 캐시된 문자열입니다.

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

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

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

      또는

    • 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 ModifyCachedString(ByVal documentPath As String)
    Dim runtimeVersion As Integer = 0
    Dim serverDocument1 As ServerDocument = Nothing

    Try
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath)
        If runtimeVersion <> 3 Then
            MessageBox.Show("This document does not have a Visual Studio Tools for Office " & _
                "customization, or it has a customization that was created with a version of " & _
                "the runtime that is incompatible with this version of the ServerDocument class.")
            Return
        End If

        If ServerDocument.IsCacheEnabled(documentPath) Then
            serverDocument1 = New ServerDocument(documentPath)
            Dim hostItem1 As CachedDataHostItem = _
                serverDocument1.CachedData.HostItems("ExcelWorkbook1.Sheet1")
            Dim dataItem1 As CachedDataItem = hostItem1.CachedData("CachedString")

            If dataItem1 IsNot Nothing AndAlso _
                Type.GetType(dataItem1.DataType).Equals(GetType(String)) Then

                dataItem1.SerializeDataInstance("This is the new cached string value.")
                serverDocument1.Save()
            End If
        Else
            MessageBox.Show("The specified document does not have cached data.")
        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
    End Try
End Sub
private void ModifyCachedString(string documentPath)
{
    int runtimeVersion = 0;
    ServerDocument serverDocument1 = null;

    try
    {
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath);

        if (runtimeVersion != 3)
        {
            MessageBox.Show("This document does not have a Visual Studio Tools for " +
                "Office customization, or it has a customization that was created with " +
                "a version of the runtime that is incompatible with this version of the " +
                "ServerDocument class.");
            return;
        }

        if (ServerDocument.IsCacheEnabled(documentPath))
        {
            serverDocument1 = new ServerDocument(documentPath);
            CachedDataHostItem hostItem1 = 
                serverDocument1.CachedData.HostItems["ExcelWorkbook1.Sheet1"];
            CachedDataItem dataItem1 = hostItem1.CachedData["CachedString"];

            if (dataItem1 != null &&
                Type.GetType(dataItem1.DataType) == typeof(string))
            {
                dataItem1.SerializeDataInstance("This is the new cached string value.");
                serverDocument1.Save();
            }
        }
        else
        {
            MessageBox.Show("The specified document does not have cached data.");
        }
    }
    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();
    }
}

.NET Framework 보안

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

참고 항목

참조

ServerDocument 클래스

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