Пример #1
0
        //https://web.archive.org/web/20130921190426/http://tech.pro/tutorial/798/csharp-tutorial-xml-serialization
        public static string SaveProject(Project project)
        {
            string status = project.Name + " Saved!";

            if (!Directory.Exists("Projects"))
            {
                Directory.CreateDirectory("Projects");
            }

            if (!File.Exists(project.Name))
            {
                File.Delete(project.Name);
            }

            try
            {
                //XmlSerializer serializer = new XmlSerializer(typeof(Project));
                //TextWriter textWriter = new StreamWriter(@"Projects\" + project.Name + ".xml");
                //serializer.Serialize(textWriter, project);
                //textWriter.Close();
                XMLGenerator xml = new XMLGenerator(project);
                CreateDocument("Projects", xml.DocumentName, "xml", xml.GenerateDoc(), true);
            }
            catch (Exception ex)
            {
                status = ex.ToString();
            }

            return(status);
        }
Пример #2
0
        //https://web.archive.org/web/20130921190426/http://tech.pro/tutorial/798/csharp-tutorial-xml-serialization
        public static string SaveProject(Project project)
        {
            string status = project.Name + " Saved!";

            if (!Directory.Exists("Projects"))
            {
                Directory.CreateDirectory("Projects");
            }

            if (!File.Exists(project.Name))
            {
                File.Delete(project.Name);
            }

            try
            {
                //XmlSerializer serializer = new XmlSerializer(typeof(Project));
                //TextWriter textWriter = new StreamWriter(@"Projects\" + project.Name + ".xml");
                //serializer.Serialize(textWriter, project);
                //textWriter.Close();
                XMLGenerator xml = new XMLGenerator(project);
                CreateDocument("Projects", xml.DocumentName, "xml", xml.GenerateDoc(), true);
            }
            catch (Exception ex)
            {
                status = ex.ToString();
            }

            return status;
        }