locked
xml extension changing to x01 RRS feed

  • Question

  • Hi,

    I am using below code to create an XML file but the problem here that the name 28072019.xml is created as 28072019.x0l

    Why is that?

    Here is the code:

    System.IO.Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MaxMon"));
    
    string file_name = DateTime.Today.ToString("ddMMyyyy.xml");
    
    string file_path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MaxMon\\" + file_name);
    
    System.Diagnostics.Debug.WriteLine(file_path);
    
    XmlDocument xml_document = new XmlDocument();
    
    if (File.Exists(file_path))
    {
        xml_document.Load(file_path);
    }
    else
    {
        XmlNode docNode = xml_document.CreateXmlDeclaration("1.0", "UTF-8", null);
        xml_document.AppendChild(docNode);
    
        XmlNode MaxMonNode = xml_document.CreateElement("MaxMon");
        xml_document.AppendChild(MaxMonNode);
    }
    
    XmlNode refElem = xml_document.DocumentElement.FirstChild;
    
    XmlNode LogNode = xml_document.CreateElement("Log");
    XmlAttribute LogAttribute = xml_document.CreateAttribute("DateTime");
    LogAttribute.Value = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss");
    LogNode.Attributes.Append(LogAttribute);
    
    xml_document.DocumentElement.InsertBefore(LogNode, refElem);
    
    XmlNode WhereNode = xml_document.CreateElement("Where");
    WhereNode.InnerText = "This is Where4 Comes Here";
    LogNode.AppendChild(WhereNode);
    
    XmlNode CategoryNode = xml_document.CreateElement("Category");
    CategoryNode.InnerText = "This is Category3 Comes Here";
    LogNode.AppendChild(CategoryNode);
    
    XmlNode DetailsNode = xml_document.CreateElement("Details");
    DetailsNode.InnerText = "This is Details3 Comes Here";
    LogNode.AppendChild(DetailsNode);
    
    xml_document.Save(file_path);
    

    Thanks,

    Jassim

    Sunday, July 28, 2019 6:54 PM

Answers

  • Try this:

    string file_name = DateTime.Today.ToString( "ddMMyyyy'.xml'" );

    • Marked as answer by Jassim Rahma Monday, July 29, 2019 2:04 PM
    Monday, July 29, 2019 4:38 AM