Click here to Skip to main content
15,885,365 members
Articles / Programming Languages / C#

XmlStore Part 2: Printing DataGridView Contents

Rate me:
Please Sign up or sign in to vote.
4.71/5 (7 votes)
18 Mar 2007CPOL7 min read 70K   3.4K   51  
A utility to read, edit, encrypt, decrypt, write and print XmlStore files
using System;
using System.Windows.Forms;

namespace VVX
{
    /// <summary>
    /// Simple class to simplify access to OpenFileDialog and SaveFileDialog
    /// WARNING: By no means complete!!!
    /// </summary>
    public static class FileDialog
    {
        public enum FileType
        {
            All,
            Image,
            Text,
            XML
        }

        public static string GetFilters(FileType enFileType)
        {
            string sRet = "";

            switch (enFileType)
            {
                default:
                case FileType.All:
                    break;

                case FileType.Image:
                    sRet = "Image Files(*.BMP;*.JPG;*.GIF;*.PNG)|*.BMP;*.JPG;*.GIF;*.PNG";
                    break;

                case FileType.Text :
                    sRet = "Text Files(*.TXT;*.CSV)|*.TXT;*.CSV";
                    break;

                case FileType.XML:
                    sRet = "XML Files(*.XML)|*.XML";
                    break;
            }

            if (sRet.Length > 0)
                sRet += "|";
            sRet += "All files (*.*)|*.*";

            return sRet;
        }

        public static string GetFilenameToOpen(FileType enFileType)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter = GetFilters(enFileType);
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                return dlg.FileName;
            }
            return "";
        }

        public static string GetFilenameToSave(FileType enFileType, string sFile)
        {
            SaveFileDialog dlg = new SaveFileDialog();

            dlg.Filter = GetFilters(enFileType);
            dlg.FileName = sFile;
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                return dlg.FileName;
            }
            return "";
        }
    }
}

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
Software Developer
United States United States
An old dog trying to learn new tricks!

Comments and Discussions