Aracılığıyla paylaş


ServerDocument.Save Yöntem

Kullanarak belgede yapılan değişiklikleri kaydeder ServerDocument sınıfı.

Ad alanı:  Microsoft.VisualStudio.Tools.Applications
Derleme:  Microsoft.VisualStudio.Tools.Applications.ServerDocument (Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll içinde)

Sözdizimi

'Bildirim
Public Sub Save
public void Save()

Özel Durumlar

Exception Koşul
DocumentClosedException

ServerDocument Kapatıldı.

MissingHostItemIdException

Id Özelliği, bir CachedDataHostItem olan nullnull başvuru (Visual Basic'te Nothing) ya da boş.

MissingDataIdException

Id Özelliği, bir CachedDataItem olan nullnull başvuru (Visual Basic'te Nothing) ya da boş.

MissingTypeException

DataType Özelliği, bir CachedDataItem olan nullnull başvuru (Visual Basic'te Nothing) ya da boş.

Notlar

Save Yöntemi, belgede url dağıtım listesi veya önbelleğe alınmış verileri yapmış olduğunuz değişiklikleri kaydeder.Siz oluşturduysanız, ServerDocument nesne disk üzerindeki bir belge kullanarak bu yöntem, bu değişiklikleri diske kaydeder.Siz oluşturduysanız, ServerDocument nesnesi bellekte bir belgeyi kullanarak bu yöntem, bu değişiklikleri ara belleğe kaydeder.

Örnekler

Aşağıdaki kod örneği, yeni bir oluşturur ServerDocument belirtilen bir Excel çalışma çalışma kullanarak önbelleğe alınmış bir dize değerini değiştirir SerializeDataInstance yöntemi ve sonra değişikliği kullanarak kaydeder, Save yöntemi.

Bu örnek aşağıdakileri gerektirir:

  • Olan Excel belge düzeyinde özelleştirme bir Sheet1 , sınıf ExcelWorkbook1 ad ve önbelleğe alınmış bir dize Sheet1 adında bir sınıfı CachedString.

  • Konsol uygulaması projesi veya başka bir Office proje.

  • Aşağıdaki derlemeler başvuruları:

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll ve Microsoft.VisualStudio.Tools.Applications.Runtime.dll (eğer proje .NET Framework 4'i hedefliyorsa).

      or

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll ve Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (, Proje hedefleri.net Framework 3.5).

  • Imports(Visual Basic için) veya using (için C#) ifadeleri için Microsoft.VisualStudio.Tools.Applications ve Microsoft.VisualStudio.Tools.Applications.Runtime kod dosyanızı üstündeki ad.

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 Güvenliği

Ayrıca bkz.

Başvuru

ServerDocument Sınıf

Microsoft.VisualStudio.Tools.Applications Ad Alanı