Export (0) Print
Expand All

XmlDataSource.Save Method

Saves the XML data currently held in memory by the XmlDataSource control to disk if the DataFile property is set.

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

member Save : unit -> unit

ExceptionCondition
InvalidOperationException

XML data was loaded using the Data property instead of the DataFile property.

- or -

A URL is specified for the DataFile property; however, the XmlDataSource control does not have the correct permissions for the Web resource.

NotSupportedException

A URL is specified for the DataFile property; however, it is not an HTTP-based URL.

- or -

A design-time relative path was not mapped correctly by the designer before using the XmlDataSource control.

HttpException

Access is denied to the path specified for the DataFile property.

While the XmlDataSource control is typically used in read-only data-binding scenarios, you can use the XmlDataSource control to edit XML data in the underlying XML data file. In these scenarios, XML data is loaded from an XML file by the XmlDataSource control. You modify the XmlDataDocument in memory using the GetXmlDocument method, and then save to the XML data file by calling the Save method. This editable XML scenario is possible when the following conditions are met:

  • The XML data is loaded from an XML file indicated by the DataFile property, not from inline XML data specified in the Data property.

  • No XSLT transformation is specified in the Transform or TransformFile properties.

The Save method does not handle concurrent save operations by different requests. If more than one user is editing an XML file through the XmlDataSource control, there is no guarantee that all users are operating with the same data. It is also possible for a Save operation to fail due to these same concurrency issues.

This section contains two code examples. The first code example demonstrates how to use an XmlDataSource control with a TreeView control to display and edit XML data contained in an XML file. The second code example demonstrates how to use an XmlDataSource control with a templated Repeater control to display and edit XML data contained in an XML file.

The following code example demonstrates how to use an XmlDataSource control with a TreeView control to display and edit XML data contained in an XML file. The data is manipulated in memory using the GetXmlDocument method every time you select a TreeView node, and is then saved to the XML file. Finally, DataBind is called on the TreeView control to refresh the data that it displays.

No code example is currently available or this language may not be supported.

The following code example demonstrates how to use an XmlDataSource control with a templated Repeater control to display and edit XML data contained in an XML file. As with the previous example, the data is manipulated in memory using the XmlDataDocument object retrieved by the GetXmlDocument method. Finally, DataBind is called on the TreeView control to refresh the data that it displays.

No code example is currently available or this language may not be supported.

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

<?xml version="1.0" encoding="utf-8"?>
 <bookstore xmlns:bk="urn:samples">
   <book genre="novel" publicationdate="1999" bk:ISBN="0000000000">
     <title>Secrets of Silicon Valley</title>
     <author>
       <first-name>Sheryl</first-name>
       <last-name>Hunter</last-name>
     </author>
     <price>24.95</price>" 
     </book>
   <book genre="novel" publicationdate="1985" bk:ISBN="1111111111">
     <title>Straight Talk About Computers</title>
     <author>
       <first-name>Dean</first-name>
       <last-name>Straight</last-name>
     </author>
     <price>29.95</price>
   </book>
</bookstore>

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft