ScrewTurn.Wiki.Tools.ExtractDirectoryName C# (CSharp) Method

ExtractDirectoryName() public static method

Extracts the directory name from a path used in the Files Storage Providers.
public static ExtractDirectoryName ( string path ) : string
path string The path, for example '/folder/blah/'.
return string
        public static string ExtractDirectoryName(string path)
        {
            path = path.Trim('/');

            int idx = path.LastIndexOf("/");
            return idx != -1 ? path.Substring(idx + 1) : path;
        }

Usage Example

示例#1
0
        private List <TreeElement> BuildImagesSubTree(IFilesStorageProviderV30 provider, string path)
        {
            IEnumerable <string> dirs;
            IEnumerable <string> files;

            if (chkImageAttachments.Checked)
            {
                // Load page attachments
                dirs  = Enumerable.Empty <string>();
                files = provider.ListPageAttachments(currentPage);
            }
            else
            {
                // Load files
                dirs  = provider.ListDirectories(path);
                files = provider.ListFiles(path);
            }

            List <TreeElement> result = new List <TreeElement>(100);

            foreach (string d in dirs)
            {
                TreeElement item = new TreeElement(d, Tools.ExtractDirectoryName(d),
                                                   BuildImagesSubTree(provider, d));
                // Do not display empty folders to reduce "noise"
                if (item.SubItems.Count > 0)
                {
                    result.Add(item);
                }
            }

            foreach (string f in files)
            {
                if (IsImage(f))
                {
                    string      name = provider.GetType().ToString() + "|" + f;
                    TreeElement item = new TreeElement(name,
                                                       @"<img src=""Thumb.aspx?Provider=" + provider.GetType().ToString() +
                                                       @"&amp;Size=Small&amp;File=" + Tools.UrlEncode(f) +
                                                       @"&amp;Page=" + (chkImageAttachments.Checked ? Tools.UrlEncode(currentPage.FullName) : "") +
                                                       @""" alt=""" + name + @""" /><span class=""imageinfo"">" + f.Substring(f.LastIndexOf("/") + 1) + "</span>",
                                                       "javascript:return SelectImage('" +
                                                       (chkImageAttachments.Checked ? "(" + Tools.UrlEncode(currentPage.FullName) + ")" : "") + "', '" + f.Replace("'", "\\\\\\'") + "', '" +
                                                       (chkImageAttachments.Checked ? currentPage.FullName : "") + "');");
                    result.Add(item);
                }
            }

            return(result);
        }
All Usage Examples Of ScrewTurn.Wiki.Tools::ExtractDirectoryName