示例#1
0
        private void OpenDataSourceDialogue_Load(object sender, EventArgs e)
        {
            //if FileType is not defined try to get type from the registry
            if (FileType == null)
            {
                FileType += x =>
                {
                    try
                    {
                        var ext  = (new FileInfo(x)).Extension;
                        var key  = Registry.ClassesRoot.OpenSubKey(ext);
                        var type = key.GetValue("") as string;
                        key = Registry.ClassesRoot.OpenSubKey(type);
                        var desc = key.GetValue("") as string;
                        return(desc);
                    }
                    catch { return("Unknown"); }
                }
            }
            ;

            //if FolderType is not defined assume every folder is actually a folder
            if (FolderType == null)
            {
                FolderType += x => "File Folder";
            }

            if (string.IsNullOrEmpty(_startLocation))
            {
                return;
            }

            //navigate to parent of passed file
            if (!Directory.Exists(_startLocation) && File.Exists(_startLocation))
            {
                var currentlevel = Path.GetFileName(_startLocation) ?? string.Empty;
                _startLocation = _startLocation.Remove(_startLocation.Length - currentlevel.Length).TrimEnd('\\');
            }
            if (Directory.Exists(_startLocation))
            {
                NavigateToFolder(_startLocation, null);
            }
        }
        private void OpenDataSourceDialogue_Load(object sender, EventArgs e)
        {
            //if FileType is not defined try to get type from the registry
            if (FileType == null)
                FileType += x =>
                                {
                                    try
                                    {
                                        var ext = (new FileInfo(x)).Extension;
                                        var key = Registry.ClassesRoot.OpenSubKey(ext);
                                        var type = key.GetValue("") as string;
                                        key = Registry.ClassesRoot.OpenSubKey(type);
                                        var desc = key.GetValue("") as string;
                                        return (desc);
                                    }
                                    catch { return "Unknown"; }
                                };

            //if FolderType is not defined assume every folder is actually a folder
            if (FolderType == null)
                FolderType += x => "File Folder";

            if (string.IsNullOrEmpty(_startLocation)) return;

            //navigate to parent of passed file
            var currentlevel = Path.GetFileName(_startLocation) ?? string.Empty;
            _startLocation = _startLocation.Remove(_startLocation.Length - currentlevel.Length).TrimEnd('\\');
            if (Directory.Exists(_startLocation))
                NavigateToFolder(_startLocation, null);
        }