Export (0) Print
Expand All

XmlDataSource.DataFile Property

Note: This property is new in the .NET Framework version 2.0.

Specifies the file name of an XML file that the data source binds to.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public virtual string DataFile { get; set; }
/** @property */
public String get_DataFile ()

/** @property */
public void set_DataFile (String value)

public function get DataFile () : String

public function set DataFile (value : String)

Property Value

The absolute physical path or relative path of the XML file that contains data that the XmlDataSource control represents. The default value is String.Empty.

If both the DataFile and Data properties are set, the DataFile property takes precedence and the data in the XML file is used instead of the XML data specified in the Data property.

If you change the value of the DataFile property, the DataSourceChanged event is raised. If caching is enabled and you change the value of DataFile, the cache is invalidated.

The following code example demonstrates how to use an XmlDataSource control to display XML data contained in a file with a 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>
  <BODY>
    <form 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="VJ#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<HTML>
  <BODY>
    <form 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>

The XML file in the code example has the following data:

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

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft