Click here to Skip to main content
15,886,422 members
Articles / Programming Languages / Visual Basic

Database Helper v 2.0.0

Rate me:
Please Sign up or sign in to vote.
4.68/5 (75 votes)
8 Jun 2010CPOL8 min read 208.7K   21.6K   270  
An open source code generation utility with some useful features to generate procedures,class for tables and .net code for procedures automatically.
using System;
using System.Xml;
using System.Xml.Serialization;
using System.IO;


namespace SP_Gen.Classes
{
    class ConfigUtils
    {
        static string appDir = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);

        static string filename = appDir + "\\Config.xml";

        public static ConfigTemplate ReadConfig()
        {
            ConfigTemplate ct;

            if (File.Exists(filename))
            {
                FileStream fs = new FileStream(filename, FileMode.Open);
                
                try
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(ConfigTemplate));
                    ct = (ConfigTemplate)serializer.Deserialize(fs);
                }
                catch (Exception exp)
                {
                    ct = new ConfigTemplate();
                }
                finally
                {
                    fs.Close();
                }
            }
            else
            {
                ct = new ConfigTemplate();
            }

            return ct;
        }

        public static void WriteConfig(ConfigTemplate ct)
        {
            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(ConfigTemplate));
                TextWriter writer = new StreamWriter(filename);

                serializer.Serialize(writer, ct);
                writer.Close();
            }
            catch
            {

            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Database Developer
Iran (Islamic Republic of) Iran (Islamic Republic of)
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions