다음을 통해 공유


ServerDocument.Save 메서드 (2007 시스템)

업데이트: 2007년 11월

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

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

구문

Public Sub Save

Dim instance As ServerDocument

instance.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 메서드를 사용하여 변경 내용을 저장합니다.

이 예제를 사용하려면 Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll과 Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll 어셈블리에 대한 참조, Microsoft.VisualStudio.Tools.ApplicationsMicrosoft.VisualStudio.Tools.Applications.Runtime 네임스페이스에 대한 Imports(Visual Basic) 또는 using(C#) 문을 코드 파일 맨 위에 추가해야 합니다. 또한 이 예제에서는 지정된 통합 문서에 ExcelWorkbook1 네임스페이스의 Sheet1 클래스를 사용하는 사용자 지정이 있고 Sheet1 클래스에는 CachedString이라는 캐시된 문자열이 있다고 가정합니다.

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();
    }
}

권한

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

참고 항목

참조

ServerDocument 클래스

ServerDocument 멤버

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