D
dfetrow410
I am using a xsl template, but I need to create that on the fly into a
stream. As well ast the xml file generated by the database. Can anyone
help me. My working code is below....
String conn = "Password=sa;User ID=sa;Initial Catalog=pubs;Data
Source=xxxxxx";
String sql = "Select * From Royalties ";
String xslPath = "RoyaltyReportStyle.xsl";
String ServerPath = HttpContext.Current.Server.MapPath("\\" +
ConfigurationSettings.AppSettings["xmlPath"] + "\\");
//Filter for a selected author
//DataRowView item = (DataRowView)nameList.Items[index];
String filter = "Karsen";
//Get Royalty data
SqlDataAdapter adapter = new SqlDataAdapter();
SqlConnection connection = new SqlConnection(conn);
SqlCommand command = new SqlCommand(sql + "where au_lname='" +
filter + "'", connection);
adapter.SelectCommand = command;
DataSet data = new DataSet("root");
adapter.Fill(data, "royalties");
//Transform the data
// string val = HttpContext.Current.Server.MapPath("\\" +
ConfigurationSettings.AppSettings["xmlPath"] + "\\" + filter + ".xml");
data.WriteXml(ServerPath + filter + ".xml");
// data.WriteXml("C:\\Inetpub\\wwwroot\\excelTransform\\Karsen.xml");
// Create a resolver with default credentials.
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials =
System.Net.CredentialCache.DefaultCredentials;
// Create the XslTransform object.
XslTransform xslt = new XslTransform();
// Load the stylesheet.
xslt.Load("http://localhost/excelTransform/RoyaltyReportStyle.xsl",
resolver);
// Transform the file.
xslt.Transform(ServerPath + filter + ".xml", ServerPath + filter +
"Report.xml", resolver);
stream. As well ast the xml file generated by the database. Can anyone
help me. My working code is below....
String conn = "Password=sa;User ID=sa;Initial Catalog=pubs;Data
Source=xxxxxx";
String sql = "Select * From Royalties ";
String xslPath = "RoyaltyReportStyle.xsl";
String ServerPath = HttpContext.Current.Server.MapPath("\\" +
ConfigurationSettings.AppSettings["xmlPath"] + "\\");
//Filter for a selected author
//DataRowView item = (DataRowView)nameList.Items[index];
String filter = "Karsen";
//Get Royalty data
SqlDataAdapter adapter = new SqlDataAdapter();
SqlConnection connection = new SqlConnection(conn);
SqlCommand command = new SqlCommand(sql + "where au_lname='" +
filter + "'", connection);
adapter.SelectCommand = command;
DataSet data = new DataSet("root");
adapter.Fill(data, "royalties");
//Transform the data
// string val = HttpContext.Current.Server.MapPath("\\" +
ConfigurationSettings.AppSettings["xmlPath"] + "\\" + filter + ".xml");
data.WriteXml(ServerPath + filter + ".xml");
// data.WriteXml("C:\\Inetpub\\wwwroot\\excelTransform\\Karsen.xml");
// Create a resolver with default credentials.
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials =
System.Net.CredentialCache.DefaultCredentials;
// Create the XslTransform object.
XslTransform xslt = new XslTransform();
// Load the stylesheet.
xslt.Load("http://localhost/excelTransform/RoyaltyReportStyle.xsl",
resolver);
// Transform the file.
xslt.Transform(ServerPath + filter + ".xml", ServerPath + filter +
"Report.xml", resolver);