del método SPChangeTokenCollection.ToString
Obtiene la representación de cadena serializada de la colección de token de cambio.
Espacio de nombres: Microsoft.SharePoint
Ensamblado: Microsoft.SharePoint (en Microsoft.SharePoint.dll)
Sintaxis
'Declaración
Public Overrides Function ToString As String
'Uso
Dim instance As SPChangeTokenCollection
Dim returnValue As String
returnValue = instance.ToString()
public override string ToString()
Valor devuelto
Tipo: System.String
Una cadena que contiene la representación de cadena serializada de la colección.
Comentarios
Puede usar este método para serializar una colección de token de cambio antes la persistencia en un almacenamiento permanente. Para reconstruir la colección, pase la representación de cadena serializada de la colección a la sobrecarga del constructor SPChangeTokenCollection que acepta una cadena.
Ejemplos
En el siguiente ejemplo consta de dos rutinas de una aplicación más grande. La primera es un procedimiento que escribe una colección de token de cambio en un archivo en el disco. El segundo es una función que acepta un nombre de archivo como un argumento, se abre el archivo, lee la primera variable de cadena serializada que encuentra y se utiliza para crear una colección de token de cambio, el valor devuelto de la función. Tenga en cuenta que si el archivo no se encuentra o no contiene una variable de cadena con formato correctamente, la función devuelve una colección vacía.
Sub SaveTokens(ByRef tokens As SPChangeTokenCollection, ByVal filePath As String)
Using fs As FileStream = File.Create(filePath)
' Serialize the tokens
Dim bw As BinaryWriter = New BinaryWriter(fs)
Dim s As String = tokens.ToString()
bw.Write(s)
' flush and close
bw.Flush()
bw.Close()
End Using
End Sub
Function GetTokens(ByVal filePath As String) As SPChangeTokenCollection
Dim tokens As SPChangeTokenCollection = New SPChangeTokenCollection()
' If we have a persisted collection, use it
If File.Exists(filePath) Then
Using fs As FileStream = File.OpenRead(filePath)
Dim br As BinaryReader = New BinaryReader(fs)
Try
Dim s As String = br.ReadString()
' Construct a change token from string
tokens = New SPChangeTokenCollection(s)
Catch
' No serialized string, or an incorrectly formatted string.
' Do nothing. We'll return an empty collection.
Finally
br.Close()
End Try
End Using
End If
Return tokens
End Function
static void SaveTokens(SPChangeTokenCollection tokens, string filePath)
{
using (FileStream fs = File.Create(filePath))
{
// Serialize the tokens
BinaryWriter bw = new BinaryWriter(fs);
string s = tokens.ToString();
bw.Write(s);
// flush and close
bw.Flush();
bw.Close();
}
}
static SPChangeTokenCollection GetTokens(string filePath)
{
SPChangeTokenCollection tokens = new SPChangeTokenCollection();
// If we have a persisted collection, use it
if (File.Exists(filePath))
{
using (FileStream fs = File.OpenRead(filePath))
{
BinaryReader br = new BinaryReader(fs);
try
{
string s = br.ReadString();
// Construct a change token from string
tokens = new SPChangeTokenCollection(s);
}
catch
{
// No serialized string, or an incorrectly formatted string.
// Do nothing. We'll return an empty collection.
}
finally
{
br.Close();
}
}
}
return tokens;
}
Vea también
Referencia
Miembros SPChangeTokenCollection