Compartir a través de


ServerDocument (Constructor) (String) (2003 System)

Actualización: noviembre 2007

Inicializa una nueva instancia de la clase ServerDocument con la ruta de acceso completa del documento que se va a cargar.

Espacio de nombres:  Microsoft.VisualStudio.Tools.Applications.Runtime
Ensamblado:  Microsoft.VisualStudio.Tools.Applications.Runtime (en Microsoft.VisualStudio.Tools.Applications.Runtime.dll)

Sintaxis

'Declaración
Public Sub New ( _
    documentPath As String _
)
'Uso
Dim documentPath As String

Dim instance As New ServerDocument(documentPath)
public ServerDocument(
    string documentPath
)

Parámetros

  • documentPath
    Tipo: System. . :: .String

    Ruta de acceso al documento que se va a cargar en la clase.

Excepciones

Excepción Condición
ArgumentNullException

El parámetro documentPath es null Nothing nullptr referencia null (Nothing en Visual Basic) o está vacío, o se compone únicamente de caracteres de espacio en blanco.

FileNotFoundException

El archivo especificado por documentPath no existe.

IOException

El archivo especificado por documentPath es de sólo lectura o no se puede obtener acceso a él.

CannotLoadManifestException

El archivo especificado por documentPath no representa un documento con una personalización de Visual Studio Tools para Office.

Comentarios

Use este constructor para tener acceso a los datos almacenados en memoria caché o al manifiesto de aplicación en un documento que está en disco. Cuando se usa este constructor, el documento especificado se abre con acceso de lectura y escritura.

Para usar este constructor, el documento debe tener ya una personalización de Visual Studio Tools para Office. Si desea abrir un documento que no tiene todavía una personalización de Visual Studio Tools para Office, use el constructor ServerDocument..::.ServerDocument(String, Boolean) o ServerDocument..::.ServerDocument(String, Boolean, FileAccess) y establezca el parámetro onClient en true. El equipo cliente debe tener instalado Word o Excel para usar estos constructores.

Ejemplos

En el siguiente ejemplo de código se utiliza el constructor ServerDocument(String) para crear un nuevo ServerDocument que carga el documento especificado y hace cambios en los datos del documento almacenados en memoria caché. En este ejemplo se necesita una referencia al ensamblado Microsoft.VisualStudio.Tools.Applications.Runtime y una instrucción Imports (para Visual Basic) o using (para C#) para el espacio de nombres Microsoft.VisualStudio.Tools.Applications.Runtime al principio del archivo de código.

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.");
    }
}

Permisos

Vea también

Referencia

ServerDocument (Clase)

ServerDocument (Miembros)

ServerDocument (Sobrecarga)

Microsoft.VisualStudio.Tools.Applications.Runtime (Espacio de nombres)