示例#1
0
        private void FileListView_SelectedIndexChanged(object sender, EventArgs e)
        {
            ListView.SelectedListViewItemCollection items = FileListView.SelectedItems;
            _SelectedFiles = new string[items.Count];
            string separator = ExplorerHandler.PathSeparator.ToString();

            for (int x = 0; x < items.Count; x++)
            {
                _SelectedFiles[x] = SelectedFolder + (SelectedFolder.EndsWith(separator) ? "" : separator) + items[x].Text;
            }
        }
        public List <Model.File> PickFolderAndFiles()
        {
            Owner = Application.Current.MainWindow;
            if (ShowDialog().GetValueOrDefault())
            {
                if (!string.IsNullOrEmpty(SelectedFolder))
                {
                    if (!SelectedFolder.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()))
                    {
                        SelectedFolder += System.IO.Path.DirectorySeparatorChar;
                    }

                    var searchOption = SearchOption.TopDirectoryOnly;
                    if (IncludeSubfolders)
                    {
                        searchOption = SearchOption.AllDirectories;
                    }

                    var files = new List <BlobTransferUtility.Model.File>();
                    try
                    {
                        foreach (var file in Directory.GetFiles(SelectedFolder, "*", searchOption))
                        {
                            var fileInfo = new FileInfo(file);
                            files.Add(new Model.File()
                            {
                                Name             = file.Substring(SelectedFolder.Length),
                                FullFilePath     = file,
                                SizeInBytes      = fileInfo.Length,
                                RelativeToFolder = SelectedFolder,
                            });
                        }
                    }
                    catch (Exception e)
                    {
                        var stringBuilder = new StringBuilder();
                        stringBuilder.AppendFormat("{1:yyyy-MM-dd HH:mm:ss} Error!{0}", Environment.NewLine, DateTime.Now);
                        stringBuilder.AppendFormat("    Listing directories and files{0}", Environment.NewLine);
                        stringBuilder.AppendFormat("    Exception: {1}{0}{0}", Environment.NewLine, e.ToString().Replace(Environment.NewLine, Environment.NewLine + "    "));
                        OnOnError(stringBuilder.ToString());
                    }
                    return(files);
                }
                return(null);
            }
            return(null);
        }