Remarque
L’accès à cette page nécessite une autorisation. Vous pouvez essayer de vous connecter ou de modifier des répertoires.
L’accès à cette page nécessite une autorisation. Vous pouvez essayer de modifier des répertoires.
Mise à jour : novembre 2007
Enregistre toutes les modifications apportées au document en utilisant la classe ServerDocument.
Espace de noms : Microsoft.VisualStudio.Tools.Applications
Assembly : Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0 (dans Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll)
Syntaxe
Public Sub Save
Dim instance As ServerDocument
instance.Save()
public void Save()
Exceptions
| Exception | Condition |
|---|---|
| DocumentClosedException | ServerDocument a été fermé. |
| MissingHostItemIdException | La propriété Id d'un CachedDataHostItem est nullune référence null (Nothing en Visual Basic) ou est vide. |
| MissingDataIdException | La propriété Id d'un CachedDataItem est nullune référence null (Nothing en Visual Basic) ou est vide. |
| MissingTypeException | La propriété DataType d'un CachedDataItem est nullune référence null (Nothing en Visual Basic) ou est vide. |
Notes
La méthode Save enregistre toutes les modifications que vous avez apportées aux données en mémoire cache ou à l'URL du manifeste de déploiement dans le document. Si vous avez créé l'objet ServerDocument en utilisant un document sur disque, cette méthode enregistre ces modifications sur disque. Si vous avez créé l'objet ServerDocument en utilisant un document en mémoire, cette méthode enregistre ces modifications dans la mémoire tampon.
Exemples
L'exemple de code suivant crée un ServerDocument pour un classeur Excel spécifié, modifie la valeur d'une chaîne mise en cache dans une feuille de calcul à l'aide de la méthode SerializeDataInstance, puis enregistre la modification à l'aide de la méthode Save.
Cet exemple requiert une référence aux assemblys Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll et Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll et à l'instruction Imports (pour Visual Basic) ou using (pour C#) pour les espaces de noms Microsoft.VisualStudio.Tools.Applications et Microsoft.VisualStudio.Tools.Applications.Runtime en haut du fichier de code. Cet exemple suppose également que le classeur spécifié a une personnalisation avec une classe Sheet1 dans l'espace de noms ExcelWorkbook1 et une chaîne mise en cache dans la classe Sheet1 nommée CachedString.
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();
}
}
Autorisations
- Confiance totale accordée à l'appelant immédiat. Ce membre ne peut pas être utilisé par du code d'un niveau de confiance partiel. Pour plus d'informations, consultez Utilisation de bibliothèques à partir de code d'un niveau de confiance partiel.