CachedDataItem (Clase) (2007 System)

Actualización: noviembre 2007

Representa un objeto de datos almacenado en memoria caché de una personalización de nivel de documento que se creó con Visual Studio Tools para Office.

Espacio de nombres:  Microsoft.VisualStudio.Tools.Applications
Ensamblado:  Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0 (en Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll)

Sintaxis

<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

Comentarios

Para obtener más información sobre el almacenamiento de datos en caché para las personalizaciones de nivel de documento, vea Almacenar datos en caché e Acceso a datos de documentos en el servidor.

Nota:

Esta clase sólo se puede utilizar con soluciones de Microsoft Office Word 2007 y Microsoft Office Excel 2007. Para tener acceso a los datos almacenados en memoria caché en soluciones de Word 2003 y Excel 2003, utilice la clase CachedDataItem del espacio de nombres Microsoft.VisualStudio.Tools.Applications.Runtime de Visual Studio 2005 Tools para Office Second Edition runtime. Para obtener más información, consulte Administrar documentos en un servidor mediante la clase ServerDocument.

Ejemplos

En el ejemplo de código siguiente se examina CachedDataItem en la caché de datos de un libro de Excel y se muestra el nombre de cada objeto de datos almacenado en memoria caché.

Este ejemplo necesita una referencia a los ensamblados Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll y Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll y las instrucciones Imports (en Visual Basic) o using (en C#) para los espacios de nombres Microsoft.VisualStudio.Tools.Applications y Microsoft.VisualStudio.Tools.Applications.Runtime al principio del archivo de código.

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

Jerarquía de herencia

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

Seguridad para subprocesos

Todos los miembros static (Shared en Visual Basic) públicos de este tipo son seguros para la ejecución de subprocesos. No se garantiza que los miembros de instancias sean seguros para la ejecución de subprocesos.

Vea también

Referencia

CachedDataItem (Miembros)

Microsoft.VisualStudio.Tools.Applications (Espacio de nombres)

Otros recursos

Almacenar datos en caché

Acceso a datos de documentos en el servidor