示例#1
0
        private void bGetFilename_Click(object sender, System.EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "Data source reference files (*.dsr)|*.dsr" +
                         "|All files (*.*)|*.*";
            ofd.FilterIndex = 1;
            if (tbFilename.Text.Length > 0)
            {
                ofd.FileName = tbFilename.Text;
            }
            else
            {
                ofd.FileName = "*.dsr";
            }

            ofd.Title        = "Specify Data Source Reference File Name";
            ofd.DefaultExt   = "dsr";
            ofd.AddExtension = true;

            try
            {
                if (_FileName != null)
                {
                    ofd.InitialDirectory = Path.GetDirectoryName(_FileName.LocalPath);
                }
            }
            catch
            {
            }
            try
            {
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        string dsr = DesignerUtility.RelativePathTo(
                            Path.GetDirectoryName(_FileName.LocalPath), Path.GetDirectoryName(ofd.FileName));

                        string f = Path.GetFileNameWithoutExtension(ofd.FileName);

                        tbFilename.Text = dsr == "" ? f : dsr + Path.DirectorySeparatorChar + f;
                    }
                    catch
                    {
                        tbFilename.Text = Path.GetFileNameWithoutExtension(ofd.FileName);
                    }
                }
            }
            finally
            {
                ofd.Dispose();
            }
        }