XmlDataSource.DataFile Propiedad

Definición

Especifica el nombre de un archivo XML al que se enlaza el origen de datos.

public:
 virtual property System::String ^ DataFile { System::String ^ get(); void set(System::String ^ value); };
public virtual string DataFile { get; set; }
member this.DataFile : string with get, set
Public Overridable Property DataFile As String

Valor de propiedad

La ruta de acceso física absoluta o relativa del archivo XML que contiene los datos que representa el control XmlDataSource. El valor predeterminado es Empty.

Excepciones

El documento se está cargando.

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar un XmlDataSource control para mostrar datos XML contenidos en un archivo con un TreeView control .

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
      <asp:xmldatasource
        id="XmlDataSource1"
        runat="server"
        datafile="books.xml" />

      <!- TreeView uses hierachical data, so the
          XmlDataSource uses an XmlHierarchicalDataSourceView
          when a TreeView is bound to it. -->

      <asp:TreeView
        id="TreeView1"
        runat="server"
        datasourceid="XmlDataSource1">
        <databindings>
          <asp:treenodebinding datamember="book" textfield="title"/>
        </databindings>
      </asp:TreeView>

    </form>
  </body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
      <asp:xmldatasource
        id="XmlDataSource1"
        runat="server"
        datafile="books.xml" />

      <!- TreeView uses hierachical data, so the
          XmlDataSource uses an XmlHierarchicalDataSourceView
          when a TreeView is bound to it. -->

      <asp:TreeView
        id="TreeView1"
        runat="server"
        datasourceid="XmlDataSource1">
        <databindings>
          <asp:treenodebinding datamember="book" textfield="title"/>
        </databindings>
      </asp:TreeView>

    </form>
  </body>
</html>

El archivo XML del ejemplo de código tiene los datos siguientes:

<books>  
   <computerbooks>  
     <book title="Secrets of Silicon Valley" author="Sheryl Hunter"/>  
     <book title="Straight Talk About Computers" author="Dean Straight"/>  
     <book title="You Can Combat Computer Stress!" author="Marjorie Green"/>                  
   </computerbooks>  
   <cookbooks>  
     <book title="Silicon Valley Gastronomic Treats" author="Innes del Castill"/>  
   </cookbooks>  
</books>  

Comentarios

Si se establecen las DataFile propiedades y Data , la DataFile propiedad tiene prioridad y los datos del archivo XML se usan en lugar de los datos XML especificados en la Data propiedad .

Si cambia el valor de la DataFile propiedad , se genera el DataSourceChanged evento . Si el almacenamiento en caché está habilitado y cambia el valor de DataFile, la memoria caché se invalida.

Se aplica a

Consulte también