Metoda ServerDocument.Save —

Powoduje zapisanie wszystkich zmian wprowadzonych do dokumentu za pomocą ServerDocument klasy.

Przestrzeń nazw:  Microsoft.VisualStudio.Tools.Applications
Zestaw:  Microsoft.VisualStudio.Tools.Applications.ServerDocument (w Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll)

Składnia

'Deklaracja
Public Sub Save
public void Save()

Wyjątki

Wyjątek Warunek
DocumentClosedException

ServerDocument Został zamknięty.

MissingHostItemIdException

Id Właściwość CachedDataHostItem jest nullodwołanie o wartości null (Nothing w języku Visual Basic) lub jest pusty.

MissingDataIdException

Id Właściwość CachedDataItem jest nullodwołanie o wartości null (Nothing w języku Visual Basic) lub jest pusty.

MissingTypeException

DataType Właściwość CachedDataItem jest nullodwołanie o wartości null (Nothing w języku Visual Basic) lub jest pusty.

Uwagi

Save Metoda zapisuje zmiany do rozmieszczania manifest adres URL w dokumencie lub zostały wprowadzone do pamięci podręcznej danych.Jeśli utworzono ServerDocument obiektu za pomocą dokumentu na dysku, Metoda ta powoduje zapisanie tych zmian na dysku.Jeśli utworzono ServerDocument obiektu za pomocą dokumentu w pamięci, ta metoda zapisuje te zmiany do bufora pamięci.

Przykłady

Poniższy przykład kodu tworzy nowy ServerDocument określony skoroszyt programu Excel, modyfikuje wartość ciągu, który jest buforowany w arkuszu przy użyciu SerializeDataInstance metodę, a następnie zapisuje zmiany za pomocą Save metoda.

W tym przykładzie wymaga:

  • Dostosowywanie poziomie dokumentu dla programu Excel, który ma Sheet1 klasy w ExcelWorkbook1 obszar nazw i ciągu buforowany w Sheet1 klasę o nazwie CachedString.

  • Projekt aplikacji konsoli lub innych projektów nienależących do pakietu Office.

  • Odwołania do następujących zestawów:

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll i Microsoft.VisualStudio.Tools.Applications.Runtime.dll (jeśli cele projektu .NET Framework 4 lub .NET Framework 4.5).

      lub

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll i Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (Jeśli projekt jest przeznaczony dla.NET Framework 3.5).

  • Imports(dla Visual Basic) lub using (w przypadku C#) oświadczenia dla Microsoft.VisualStudio.Tools.Applications i Microsoft.VisualStudio.Tools.Applications.Runtime obszarów nazw u góry pliku kodu.

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

Zabezpieczenia programu .NET Framework

Zobacz też

Informacje

ServerDocument Klasa

Przestrzeń nazw Microsoft.VisualStudio.Tools.Applications