Esempio n. 1
0
        /// <summary>
        /// Populates items List with folders and files
        /// </summary>
        /// <param name="items"></param>
        /// <param name="fullPath"></param>
        /// <param name="datatype"></param>
        private static void GetItems(ref List <DataItem> items, string fullPath, DataType datatype)
        {
            try
            {
                string[] itemsToAdd = null;
                switch (datatype)
                {
                case DataType.FolderClosed:
                    itemsToAdd = Directory.GetDirectories(fullPath);
                    break;

                case DataType.File:
                    itemsToAdd = Directory.GetFiles(fullPath);
                    break;
                }

                if (itemsToAdd != null && itemsToAdd.Length > 0)
                {
                    items.AddRange(itemsToAdd.Select(item => new DataItem
                    {
                        FullPath = item,
                        Type     = datatype
                    }));
                }
            }
            catch (Exception ex)
            {
                ErrorManager.HandleException(ex);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Perform delete for the given item
        /// </summary>
        /// <param name="path">full item path</param>
        /// <returns></returns>
        private bool Delete(string path)
        {
            try
            {
                var doDelete = MessageBox.Show(string.Format("Really want to delete {0}", path), "DELETE", MessageBoxButton.YesNo);
                if (doDelete == MessageBoxResult.Yes)
                {
                    var attributes = File.GetAttributes(path) & FileAttributes.Directory;
                    if (attributes == FileAttributes.Directory)
                    {
                        Directory.Delete(path);
                    }
                    else
                    {
                        File.Delete(path);
                    }

                    return(true);
                }
            }
            catch (Exception ex)
            {
                ErrorManager.HandleException(ex);
            }

            return(false);
        }