Metoda CachedDataItem.SerializeDataInstance —
Szereguje danych do obiektu buforowanych danych, który jest reprezentowany przez CachedDataItem.
Przestrzeń nazw: Microsoft.VisualStudio.Tools.Applications
Zestaw: Microsoft.VisualStudio.Tools.Applications.ServerDocument (w Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll)
Składnia
'Deklaracja
Public Sub SerializeDataInstance ( _
value As Object _
)
public void SerializeDataInstance(
Object value
)
Parametry
- value
Typ: System.Object
Obiekt, który zawiera dane, które chcesz zapisać do obiektu w pamięci podręcznej danych.
Uwagi
Użyj SerializeDataInstance metody do inicjowania lub zmodyfikować wartość obiektów buforowanych danych.Ta metoda szereguje value parametr do buforowanych danych obiekt, który CachedDataItem reprezentuje.Dokonywanie zmian w wartości określonych danych w obiekcie złożonych buforowanych danych, takich jak DataSet lub DataTabledeserializacji reprezentacji XML buforowane dane do nowej instancji obiektu w pamięci podręcznej, wprowadzić zmiany do tej kopii, a następnie użyj SerializeDataInstance metoda serializować zmian z powrotem do pamięci podręcznej danych.Aby uzyskać więcej informacji, zobacz Uzyskiwanie dostępu do danych w dokumentach na serwerze i Wskazówki: zmiana danych z pamięci podręcznej ze skoroszytu na serwerze.
Metoda ta korzysta z formatu w formacie DiffGram dla szeregowania DataSet, DataTablei wpisane obiektów dataset w pamięci podręcznej danych.Gwarantuje to, że zmiany w pamięci podręcznej danych w dokumentów w trybie offline są prawidłowo wysyłane do serwera.
Przykłady
Następujący kod w przykładzie wykorzystano SerializeDataInstance metodę, aby zmodyfikować wartość ciągu, który jest buforowany w arkuszu skoroszytu programu Excel.
W tym przykładzie wymaga:
Dostosowywanie poziomie dokumentu do programu Excel, który ma Sheet1 klasy w ExcelWorkbook1 obszaru nazw i ciąg znaków buforowanych w Sheet1 klasę o nazwie CachedString.
Projekt aplikacji konsoli lub innego projektu nienależących do pakietu Office.
Odwołania do następujących zestawów:
Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll
Microsoft.VisualStudio.Tools.Applications.Runtime.dll
Imports(dla języka Visual Basic) lub using (w języku C#) oświadczenia dla Microsoft.VisualStudio.Tools.Applications i Microsoft.VisualStudio.Tools.Applications.Runtime nazw u góry pliku kodu.
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();
}
}
Zabezpieczenia programu .NET Framework
- Pełne zaufanie do bezpośredniego wywołującego. Tego elementu członkowskiego nie można używać w kodzie częściowo zaufanym. Aby uzyskać więcej informacji, zobacz Używanie bibliotek pochodzących z częściowo zaufanego kodu.
Zobacz też
Informacje
Przestrzeń nazw Microsoft.VisualStudio.Tools.Applications