Compartilhar via


ServerDocument.Save O método (sistema de 2007)

Salva as alterações foram feitas no documento usando o ServerDocument classe.

Namespace:  Microsoft.VisualStudio.Tools.Applications
Assembly:  Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0 (em Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll)

Sintaxe

Public Sub Save

Dim instance As ServerDocument

instance.Save()
public void Save()

Exceções

Exceção Condição
DocumentClosedException

The ServerDocument foi fechado.

MissingHostItemIdException

The Id propriedade de um CachedDataHostItem é nulluma referência nula (Nothing no Visual Basic) ou vazio.

MissingDataIdException

The Id propriedade de um CachedDataItem é nulluma referência nula (Nothing no Visual Basic) ou vazio.

MissingTypeException

The DataType propriedade de um CachedDataItem é nulluma referência nula (Nothing no Visual Basic) ou vazio.

Comentários

The Save método salva as alterações que você fez os dados armazenados em cache ou à implantação de manifesto URL do documento. Se você tiver criado o ServerDocument objeto por meio de um documento no disco, esse método salva essas alterações em disco. Se você tiver criado o ServerDocument objeto usando um documento na memória, esse método salva essas alterações o buffer de memória.

Exemplos

O exemplo de código a seguir cria um novo ServerDocument para uma pasta de trabalho do Excel especificada modifica o valor de uma seqüência de caracteres armazenados em cache em uma planilha usando o SerializeDataInstance método e, em seguida, salva a alterar, usando o Save método.

Este exemplo requer uma referência aos assemblies Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll e Microsoft.VisualStudio.Tools.Applications.tempo de execução.v9.0.dll e Imports (para Visual Basic) ou using (para translation from VPE for Csharp) instruções para Microsoft.VisualStudio.Tools.Applications e Microsoft.VisualStudio.Tools.Applications.Runtime espaços para nome na parte superior do seu arquivo de código. Este exemplo também assume que a pasta de trabalho especificada tem uma personalização com um Sheet1 classe na ExcelWorkbook1 namespace e uma seqüência de caracteres em cache na Sheet1 classe chamada CachedString.

PrivateSub ModifyCachedString(ByVal documentPath AsString)
    Dim runtimeVersion AsInteger = 0
    Dim serverDocument1 As ServerDocument = NothingTry
        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.")
            ReturnEndIfIf 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 IsNotNothingAndAlso _
                Type.GetType(dataItem1.DataType).Equals(GetType(String)) Then

                dataItem1.SerializeDataInstance("This is the new cached string value.")
                serverDocument1.Save()
            EndIfElse
            MessageBox.Show("The specified document does not have cached data.")
        EndIfCatch 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.")
    FinallyIfNot (serverDocument1 IsNothing) Then
            serverDocument1.Close()
        EndIfEndTryEndSub
privatevoid 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();
    }
}

Permissões

Consulte também

Referência

ServerDocument Classe

Membros ServerDocument

Namespace Microsoft.VisualStudio.Tools.Applications