ServerDocument.IsCacheEnabled Method (2003 System)
Gets a value that indicates whether the specified document has a data cache.
Namespace: Microsoft.VisualStudio.Tools.Applications.Runtime
Assembly: Microsoft.VisualStudio.Tools.Applications.Runtime (in Microsoft.VisualStudio.Tools.Applications.Runtime.dll)
Syntax
'Declaration
Public Shared Function IsCacheEnabled ( _
documentPath As String _
) As Boolean
'Usage
Dim documentPath As String
Dim returnValue As Boolean
returnValue = ServerDocument.IsCacheEnabled(documentPath)
public static bool IsCacheEnabled(
string documentPath
)
Parameters
- documentPath
Type: System.String
The path of the document that you want to check.
Return Value
Type: System.Boolean
true if the specified document has a data cache; otherwise, false.
Exceptions
Exception | Condition |
---|---|
ArgumentNullException | The documentPath parameter is nulla null reference (Nothing in Visual Basic) or empty or consists entirely of white space characters. |
FileNotFoundException | The file in documentPath does not exist. |
Remarks
This method indicates only whether the document has a data cache, not whether the data cache actually contains data. If the document has a data cache that contains no data in it, this method still returns true.
Examples
The following code example creates a new ServerDocument, and then modifies data that is cached in the data island. The example first uses the IsCacheEnabled method to verify that the workbook has a data cache. This example requires a reference to the Microsoft.VisualStudio.Tools.Applications.Runtime assembly, and an Imports (for Visual Basic) or using (for C#) statement for the Microsoft.VisualStudio.Tools.Applications.Runtime namespace at the top of your code file.
Private customerOrdersSet As DataSet
Private Sub LoadCachedData(ByVal fileName As String)
If ServerDocument.IsCacheEnabled(fileName) Then
Dim serverDocument1 As ServerDocument = Nothing
Try
serverDocument1 = New ServerDocument(fileName)
customerOrdersSet = New DataSet()
' Identify the namespace and the class that
' contains the cached data object.
Dim hostItem1 As CachedDataHostItem = _
serverDocument1.CachedData.HostItems( _
"DataCachingSource.ThisWorkbook")
' Identify the name of the cached data object.
Dim dataItem1 As CachedDataItem = _
hostItem1.CachedData("customerOrdersCached")
' Read the cached data into the local DataSet.
If Nothing <> dataItem1.Xml AndAlso _
Nothing <> dataItem1.Schema Then
Dim xmlReader As New System.IO.StringReader( _
dataItem1.Xml)
Dim schemaReader As New System.IO.StringReader( _
dataItem1.Schema)
customerOrdersSet.ReadXmlSchema(schemaReader)
customerOrdersSet.ReadXml(xmlReader)
' Modify the data.
Dim row As DataRow
For Each row In customerOrdersSet.Tables(0).Rows
Dim orders As Integer = Fix(row("OrderQuantity"))
row("OrderQuantity") = orders * 2
Next row
' Write the modified data back to the
' cached data in the worksheet.
dataItem1.SerializeDataInstance(customerOrdersSet)
serverDocument1.Save()
End If
Finally
If Not serverDocument1 Is Nothing Then
serverDocument1.Close()
End If
End Try
Else
MsgBox("The specified document does not have " + _
"a data cache.")
End If
End Sub
private DataSet customerOrdersSet;
private void LoadCachedData(string fileName)
{
if (ServerDocument.IsCacheEnabled(fileName))
{
ServerDocument serverDocument1 = null;
try
{
serverDocument1 = new ServerDocument(fileName);
customerOrdersSet = new DataSet();
// Identify the namespace and the class that contains
// the cached data object.
CachedDataHostItem hostItem1 =
serverDocument1.CachedData.HostItems[
"DataCachingSource.ThisWorkbook"];
// Identify the name of the cached data object.
CachedDataItem dataItem1 = hostItem1.CachedData[
"customerOrdersCached"];
// Read the cached data into the local DataSet.
if (null != dataItem1.Xml && null != dataItem1.Schema)
{
System.IO.StringReader xmlReader =
new System.IO.StringReader(dataItem1.Xml);
System.IO.StringReader schemaReader =
new System.IO.StringReader(dataItem1.Schema);
customerOrdersSet.ReadXmlSchema(schemaReader);
customerOrdersSet.ReadXml(xmlReader);
// Modify the data.
foreach (DataRow row in
customerOrdersSet.Tables[0].Rows)
{
int orders = (int)row["OrderQuantity"];
row["OrderQuantity"] = orders * 2;
}
// Write the modified data back to the
// cached data in the worksheet.
dataItem1.SerializeDataInstance(customerOrdersSet);
serverDocument1.Save();
}
}
finally
{
if (serverDocument1 != null)
serverDocument1.Close();
}
}
else
{
MessageBox.Show("The specified document does not have " +
"a data cache.");
}
}
Permissions
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.