Share via


XmlDataSource.DataFile Propriedade

Definição

Especifica o nome do arquivo de um arquivo XML ao qual a fonte de dados é associada.

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 da propriedade

O caminho físico absoluto ou relativo do arquivo XML que contém os dados que o controle XmlDataSource representa. O valor padrão é Empty.

Exceções

O documento está carregando.

Exemplos

O exemplo de código a seguir demonstra como usar um XmlDataSource controle para exibir dados XML contidos em um arquivo com um TreeView controle .

<%@ 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>

O arquivo XML no exemplo de código tem os seguintes dados:

<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>  

Comentários

Se as DataFile propriedades e Data estiverem definidas, a DataFile propriedade terá precedência e os dados no arquivo XML serão usados em vez dos dados XML especificados na Data propriedade .

Se você alterar o valor da DataFile propriedade , o DataSourceChanged evento será gerado. Se o cache estiver habilitado e você alterar o valor de DataFile, o cache será invalidado.

Aplica-se a

Confira também