Friday, October 22, 2010

Create XmlFile dynamically attaching Todays Date to its Name

xmlcontent is a string containg the xml data.It is used to generate xml content for the newly created xml file.

                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml(xmlcontent);

                    string date = System.DateTime.Now.ToString();
                    date = date.Replace("/", "_");
                    date = date.Replace(":", "-");
                    date = date.Replace(" ", "$");
                    string filename = date + "@Test.xml";
                    FileInfo fi = new FileInfo(MapPath("Temp//") + filename);
                    FileStream fstr = fi.Create();
                    fstr.Flush();
                    fstr.Close();

                    string filepath = Server.MapPath("Temp//");
                    xmlDoc.Save(filepath + filename);

No comments: