Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

FileSystemDataSource-kontroll för EPiServer 7.5 (webforms)

Vote:
 

Hello!

I ett uppgraderingsprojekt till EPiServer 7.5 används FileSystemDataSource-kontrollen för att lista filer i en asp:TreeView. Detta fungerar inte för nya mediaystemet eftersom FSDS-kontrollen är byggd för UFS. Finns det en ny kontroll för detta eller är det roll-your-own-dags?

Någon som stött på samma problem?

Gracias.

#109762
Oct 14, 2014 13:55
Vote:
 

Actually, the same problem has occurred to me; FileSystemDataSource is used in the legacy code (for a TreeView), but does not exist for the new Media-based file system.

Here's some code to work on as a base (it lacks icons and sorting):

        
        public class Root : IHierarchicalEnumerable
        {
            public ContentReference RootLink { get; set; }

            public Root(ContentReference rootLink)
            {
                RootLink = rootLink;
            }

            public IEnumerator GetEnumerator() { return new List<IContent> { DataFactory.Instance.Get<IContent>(RootLink) }.GetEnumerator(); }
            public IHierarchyData GetHierarchyData(object obj) { return new Node((IContent)obj, null); }
        }

        public class Children : IHierarchicalEnumerable
        {
            public Node ParentNode { get; set; }

            public Children(Node parentNode)
            {
                ParentNode = parentNode;
            }

            public IEnumerator GetEnumerator() { return ParentNode.Content.ContentLink.GetChildren<IContent>().GetEnumerator(); }
            public IHierarchyData GetHierarchyData(object obj) { return new Node((IContent)obj, ParentNode); }
        }

        public class Node : IHierarchyData
        {
            public IContent Content { get; set; }
            public Node Parent { get; set; }

            public Node(IContent content, Node parent)
            {
                Content = content;
                Parent = parent;
            }

            public bool HasChildren { get { return DataFactory.Instance.GetChildren<IContent>(Content.ContentLink).Any(); } }
            public object Item { get { return Content; } }
            public string Path
            {
                get
                {
                    var node = this;
                    var str = string.Empty;
                    do
                    {
                        if(str != string.Empty)
                        {
                            str += "/";
                        }

                        str += node.Content.Name;
                    } while ((node = node.Parent) != null);

                    return str;
                }
            }
            public string Type { get { return Content.GetType().Name; } }
            public IHierarchicalEnumerable GetChildren() { return new Children(this); }
            public IHierarchyData GetParent() { return Parent; }
        }

How to use it:

                FileTree.DataSource = new Root(content.ContentLink);
                FileTree.DataBind();
#145934
Edited, Mar 15, 2016 21:55
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.