ServerDocument.Save – metoda
Uloží změny provedené v dokumentu pomocí ServerDocument třídy.
Obor názvů: Microsoft.VisualStudio.Tools.Applications
Sestavení: Microsoft.VisualStudio.Tools.Applications.ServerDocument (v Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll)
Syntaxe
'Deklarace
Public Sub Save
public void Save()
Výjimky
Výjimka | Podmínka |
---|---|
DocumentClosedException | ServerDocument Byla ukončena. |
MissingHostItemIdException | Id Vlastnosti CachedDataHostItem je nullodkaz null (Nothing v jazyce Visual Basic) nebo je prázdný. |
MissingDataIdException | Id Vlastnosti CachedDataItem je nullodkaz null (Nothing v jazyce Visual Basic) nebo je prázdný. |
MissingTypeException | DataType Vlastnosti CachedDataItem je nullodkaz null (Nothing v jazyce Visual Basic) nebo je prázdný. |
Poznámky
Save Metoda uloží veškeré změny provedené v data uložená v mezipaměti nebo nasazení manifest adresy URL v dokumentu.Pokud jste vytvořili ServerDocument objekt pomocí dokumentu na disku, tato metoda uloží změny na disk.Pokud jste vytvořili ServerDocument objekt pomocí dokumentu v paměti, tato metoda ukládá změny do vyrovnávací paměti.
Příklady
Následující příklad kódu vytvoří nový ServerDocument pro zadaný sešit aplikace Excel, mění hodnotu řetězce mezipaměti v listu pomocí SerializeDataInstance metoda a pak uloží změny pomocí Save metoda.
Tento příklad vyžaduje:
O přizpůsobení úrovni dokumentu aplikace Excel, který má Sheet1 třída v ExcelWorkbook1 oboru názvů a řetězec v mezipaměti v Sheet1 třídu s názvem CachedString.
Projekt aplikace konzoly nebo jiného projektu mimo sadu Office.
Odkazy na následující sestavení:
Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll a Microsoft.VisualStudio.Tools.Applications.Runtime.dll (Pokud projekt cílen .NET Framework 4 nebo .NET Framework 4.5).
nebo
Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll a Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (Pokud je projekt cílen na rozhraní.NET Framework 3.5).
Imports(pro Visual Basic) nebo using (pro jazyk C#) příkazy pro Microsoft.VisualStudio.Tools.Applications a Microsoft.VisualStudio.Tools.Applications.Runtime obory názvů v horní části souboru kódu.
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();
}
}
Zabezpečení rozhraní .NET Framework
- Plná důvěra přímému volajícímu. Částečně zabezpečený kód nemůže tento člen použít. Další informace naleznete v tématu Používání knihoven z částečně důvěryhodného kódu.