Compartilhar via


CachedDataItem.Id A propriedade (sistema de 2007)

Obtém ou define o nome do objeto dados armazenados em cache que é representado pelo CachedDataItem.

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

Sintaxe

Public Property Id As String

Dim instance As CachedDataItem
Dim value As String

value = instance.Id

instance.Id = value
public string Id { get; set; }

Valor de propriedade

Tipo: System.String
O nome do objeto dados armazenados em cache que é representado pelo CachedDataHostItem.

Exemplos

O exemplo de código a seguir usa o Id propriedade para exibir os nomes dos objetos de dados em cache em uma pasta de trabalho do Excel.

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.

PrivateSub DisplayDataCacheContents(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 stringBuilder1 AsNew System.Text.StringBuilder()

            ' Display all of the cached data items             ' in the document.Dim hostItem1 As CachedDataHostItem
            ForEach hostItem1 In serverDocument1.CachedData.HostItems
                stringBuilder1.Append(vbLf & "Namespace and class: ")
                stringBuilder1.Append(hostItem1.Id & vbLf)
                Dim dataItem1 As CachedDataItem
                ForEach 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.")
        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 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();
    }
}

Permissões

Consulte também

Referência

CachedDataItem Classe

Membros CachedDataItem

Namespace Microsoft.VisualStudio.Tools.Applications