Using System.Xml;
Make one Cofiguration Folder Inside make that .xml file.
protected void btnGeneratexmlfile_Click(object sender, EventArgs e)
{
string type = "new";
Int32 queryid;
string FilePath = Request.PhysicalApplicationPath + @"Configuration\" + "QueryMaster.xml";
string SouPath = Request.PhysicalApplicationPath + "Configuration";
StringBuilder _UserInfo = new StringBuilder();
if (File.Exists(FilePath) == true)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load (FilePath);
XmlNode xmlNode = xmlDoc.SelectSingleNode("//querytrans");
if (type == "new")
queryid = 1000 + xmlNode.ChildNodes.Count + 1;
String Query = "trans type=\"new\" bookid=\"1\" assetid=\"35\" queryid=\"6\" byuserid=\"5\" byroleid=\"1\" touserid=\"4\" toroleid=\"9\" transdate=\"" + DateTime.Now.ToString() + "\"> ![CDATA[" + 12 + "]]> /trans>";
xmlNode.InnerXml = xmlNode.InnerXml + Query;
File.SetAttributes(FilePath, FileAttributes.Normal);
xmlDoc.Save(FilePath);//Append the xml file
}
else//if file not exist
{
_UserInfo.Append("?xml version=\"1.0\" encoding=\"utf-8\" ?>");
_UserInfo.Append("querytrans>");
_UserInfo.Append("/querytrans>");
StreamWriter _sw = new StreamWriter(SouPath + "\\QueryMaster.xml");
_sw.WriteLine(_UserInfo.ToString());
_sw.Flush();
_sw.Close();
_sw.Dispose();
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment