First of all the SqlDataSource web control is built on System.Data API's. If you have SQL Server 2005 you can use the "for xml path" query and get back the data as XML and stream it directly to disk using an XmlWriter as follows:
string constr
SqlConnection con = new SqlConnection(constr); con.Open(); using (con) { SqlCommand cmd = con.CreateCommand(); cmd.CommandText = "SELECT * FROM Accounts for XML PATH"; XmlReader r = cmd.ExecuteXmlReader(); XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; XmlWriter w = XmlWriter.Create(
, settings); using (w) { w.WriteStartElement("root"); // must have a root document element. while (!r.EOF) { w.WriteNode(r, true); } w.Wri****dElement(); } }
David Schmidt
Posted: XML and the .NET Framework, How to get data from a SqlDataSource in XML format