Freigeben über


CachedDataItem-Klasse (2007 System)

Aktualisiert: November 2007

Stellt ein zwischengespeichertes Datenobjekt in einer Anpassung auf Dokumentebene dar, die mithilfe von Visual Studio Tools for Office erstellt wurde.

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

Syntax

<PermissionSetAttribute(SecurityAction.Demand, Name := "FullTrust")> _
Public NotInheritable Class CachedDataItem _
    Inherits CachedDataNodeBase

Dim instance As CachedDataItem
[PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
public sealed class CachedDataItem : CachedDataNodeBase

Hinweise

Weitere Informationen über das Zwischenspeichern von Daten in Anpassungen auf Dokumentebene finden Sie unter Zwischenspeichern von Daten und unter Zugreifen auf Daten in Dokumenten auf dem Server

Hinweis:

Diese Klasse kann nur mit Projektmappen für Microsoft Office Word 2007 und Microsoft Office Excel 2007 verwendet werden. Um auf zwischengespeicherte Daten in Projektmappen für Word 2003 und Excel 2003 zuzugreifen, verwenden Sie die CachedDataItem-Klasse im Microsoft.VisualStudio.Tools.Applications.Runtime-Namespace in Laufzeit für Visual Studio 2005 Tools for Office Second Edition. Weitere Informationen finden Sie unter Verwalten von Dokumenten auf einem Server mit der ServerDocument-Klasse.

Beispiele

Im folgenden Codebeispiel wird jedes CachedDataItem im Datencache einer Excel-Arbeitsmappe untersucht, und die Namen der einzelnen zwischengespeicherten Datenobjekte werden angezeigt.

Für dieses Beispiel ist am Anfang der Codedatei ein Verweis auf die Assemblys Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll und Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll sowie auf die Anweisung Imports (für Visual Basic) oder using (für C#) für die Namespaces Microsoft.VisualStudio.Tools.Applications und Microsoft.VisualStudio.Tools.Applications.Runtime erforderlich.

Private Sub DisplayDataCacheContents(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 stringBuilder1 As New System.Text.StringBuilder()

            ' Display all of the cached data items 
            ' in the document.
            Dim hostItem1 As CachedDataHostItem
            For Each hostItem1 In serverDocument1.CachedData.HostItems
                stringBuilder1.Append(vbLf & "Namespace and class: ")
                stringBuilder1.Append(hostItem1.Id & vbLf)
                Dim dataItem1 As CachedDataItem
                For Each dataItem1 In hostItem1.CachedData
                    stringBuilder1.Append("     Data item: ")
                    stringBuilder1.Append(dataItem1.Id & vbLf)
                Next dataItem1
            Next hostItem1
            MessageBox.Show(stringBuilder1.ToString())
        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 DisplayDataCacheContents(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);
            System.Text.StringBuilder stringBuilder1 =
                new System.Text.StringBuilder();

            // Display all of the cached data items 
            // in the document.
            foreach (CachedDataHostItem hostItem1 in
                serverDocument1.CachedData.HostItems)
            {
                stringBuilder1.Append("\nNamespace and class: ");
                stringBuilder1.Append(hostItem1.Id + "\n");
                foreach (CachedDataItem dataItem1 in
                    hostItem1.CachedData)
                {
                    stringBuilder1.Append("     Data item: ");
                    stringBuilder1.Append(dataItem1.Id + "\n");
                }
            }
            MessageBox.Show(stringBuilder1.ToString());
        }
        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();
    }
}

Vererbungshierarchie

System.Object
  Microsoft.VisualStudio.Tools.Applications.CachedDataNodeBase
    Microsoft.VisualStudio.Tools.Applications.CachedDataItem

Threadsicherheit

Alle öffentlichen static (Shared in Visual Basic)-Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Siehe auch

Referenz

CachedDataItem-Member

Microsoft.VisualStudio.Tools.Applications-Namespace

Weitere Ressourcen

Zwischenspeichern von Daten

Zugreifen auf Daten in Dokumenten auf dem Server