// GET api/<controller> public JsonResult <DirectoryStruct[]> Get() { var item = _sitecoreService.GetItem <Item>("{11111111-1111-1111-1111-111111111111}"); var children = new List <DirectoryStruct>(); foreach (var child in item.Children.ToArray()) { var dir = new DirectoryStruct { Name = child.Name, ChildrenList = new List <string>() }; var nestedChildren = child.Children.ToArray(); foreach (var name in nestedChildren) { dir.ChildrenList.Add(name.Name); } if (nestedChildren.Length == 0) { var media = MediaManager.GetMedia(child); string ext = media.Extension.ToLower(); if (!(ext.Contains("gif") || ext.Contains("jpg") || ext.Contains("png"))) { continue; } } if (nestedChildren.Length == 0) { var media = MediaManager.GetMedia(child); string ext = media.Extension.ToLower(); if (!(ext.Contains("mp3") || ext.Contains("doc") || ext.Contains("docx") || ext.Contains("xls") || ext.Contains("xlsx") || ext.Contains("ppt") || ext.Contains("pptx") || ext.Contains("pdf"))) { continue; } } dir.Children = dir.ChildrenList.ToArray(); children.Add(dir); } return(Json(children.ToArray())); }
/// <summary> /// 显示主机上的文件 /// </summary> /// <param name="explorer">主机指令</param> public void ShowHostDirectory(ExplorerCode explorer) { DirectoryStruct[] directorys; FileStruct[] files; if (!explorer.Available) { MessageBox.Show("当前路径无法访问!"); return; } ltv_HostExplorer.Invoke(new ClearEvent(ListViewClear)); directorys = explorer.Directorys; files = explorer.Files; //记录当前目录(用于下载或上传文件) ltv_HostExplorer.Tag = explorer.Path; //添加回退功能 string parentPath = ICanSeeYou.Common.IO.GetParentPath(explorer.Path); DirectoryStruct lastDirectory = new DirectoryStruct(parentPath); ListViewItem lastItem = new ListViewItem(Constant.ParentPath); lastItem.ImageKey = (string)imageKey["LastPath"]; lastItem.Tag = lastDirectory; UpdateListView(lastItem); ListViewItem[] dItems = new ListViewItem[directorys.Length]; string name; for (int i = 0; i < directorys.Length; i++) { name = ICanSeeYou.Common.IO.GetName(directorys[i].Name); if (name != "") { dItems[i] = new ListViewItem(name); //文件夹图标 dItems[i].ImageKey = (string)imageKey["Directory"]; dItems[i].Tag = directorys[i]; UpdateListView(dItems[i]); } } ListViewItem[] fItems = new ListViewItem[files.Length]; string type; for (int i = 0; i < files.Length; i++) { name = ICanSeeYou.Common.IO.GetName(files[i].Name); if (name != "") { fItems[i] = new ListViewItem(name); //文件图标 type = ICanSeeYou.Common.IO.GetFileType(files[i].Name).ToLower(); if (imageKey.Contains(type)) { fItems[i].ImageKey = (string)imageKey[type]; } else { fItems[i].ImageKey = (string)imageKey["Unknown"]; } fItems[i].Tag = files[i]; UpdateListView(fItems[i]); } } }
public JsonResult <DirectoryStruct[]> Get(string path) { bool picsOnly = path.ToLower().Contains("media library"); bool docsOnly = path.ToLower().Contains("supporting documents"); if (docsOnly) { picsOnly = false; } var item = _sitecoreService.GetItem <Item>(path); var children = new List <DirectoryStruct>(); foreach (var child in item.Children.ToArray()) { var dir = new DirectoryStruct { Name = child.Name, ChildrenList = new List <string>() }; var nestedChildren = child.Children.ToArray(); foreach (var name in nestedChildren) { dir.ChildrenList.Add(name.Name); } if (nestedChildren.Length == 0 && picsOnly) { var media = MediaManager.GetMedia(child); string ext = media.Extension.ToLower(); if (!(ext.Contains("gif") || ext.Contains("jpg") || ext.Contains("png"))) { continue; } } if (nestedChildren.Length == 0 && docsOnly) { var media = MediaManager.GetMedia(child); string ext = media.Extension.ToLower(); if (!(ext.Contains("mp3") || ext.Contains("doc") || ext.Contains("docx") || ext.Contains("xls") || ext.Contains("xlsx") || ext.Contains("ppt") || ext.Contains("pptx") || ext.Contains("pdf"))) { continue; } } dir.Children = dir.ChildrenList.ToArray(); children.Add(dir); } return(Json(children.ToArray())); }
/// <summary> /// 显示主机上的文件 /// </summary> /// <param name="explorer">主机指令</param> /// <param name="lView">显示结果的列表视图控件</param> /// <param name="imageHashtable">文件图标的键值(哈希表)</param> public static void ShowHostDirectory(ExplorerCode explorer, ListView lView, Hashtable imageHashtable) { DirectoryStruct[] directorys; FileStruct[] files; if (!explorer.Available) { MessageBox.Show("当前路径无法访问!"); return; } lView.Items.Clear(); directorys = explorer.Directorys; files = explorer.Files; lView.Tag = explorer.Path; //添加回退功能 string parentPath = IO.GetParentPath(explorer.Path); DirectoryStruct lastDirectory = new DirectoryStruct(parentPath); ListViewItem lastItem = new ListViewItem(Constant.ParentPath); lastItem.ImageKey = (string)imageHashtable["LastPath"]; lastItem.Tag = lastDirectory; lView.Items.Add(lastItem); ListViewItem[] dItems = new ListViewItem[directorys.Length]; string name; for (int i = 0; i < directorys.Length; i++) { name = IO.GetName(directorys[i].Name); if (name != "") { dItems[i] = new ListViewItem(name); //文件夹图标 dItems[i].ImageKey = (string)imageHashtable["Directory"]; dItems[i].Tag = directorys[i]; lView.Items.Add(dItems[i]); } } ListViewItem[] fItems = new ListViewItem[files.Length]; string type; for (int i = 0; i < files.Length; i++) { name = IO.GetName(files[i].Name); if (name != "") { fItems[i] = new ListViewItem(name); //文件图标 type = IO.GetFileType(files[i].Name).ToLower(); if (imageHashtable.Contains(type)) { fItems[i].ImageKey = (string)imageHashtable[type]; } else { fItems[i].ImageKey = (string)imageHashtable["Unknown"]; } fItems[i].Tag = files[i]; lView.Items.Add(fItems[i]); } } }