More in this section

Forums / Developing with Sitefinity / Files Module datasource

Files Module datasource

6 posts, 0 answered
  1. Razia
    Razia avatar
    9 posts
    Registered:
    10 Jun 2010
    10 Jun 2010
    Link to this post
    Hello,

    We are using the module Files of sitefinity and it lists all the files that are found in the website directory. We want to restrict the view to certain folders only. The telerik rad grid and telerik tree view have no data source attached. Is it possible to override the binding of the two controls to a specific list of files only?

    Will be grateful for a prompt reply.
    Thanks
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    10 Jun 2010
    Link to this post
    Hello Razia,

    Thank you for using our services.

    Please take a look at this form thread: File Manager - Hide Folders.

    All the best,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Razia
    Razia avatar
    9 posts
    Registered:
    10 Jun 2010
    24 Jun 2010
    Link to this post
    Thank you for the prompt reply of the previous thread. When using the thread however, the radgrid displays all files on paging, therefore the solution does not work all the time. Is it possible to change the data source of the radgrid on need data source event?
    Thanks
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    28 Jun 2010
    Link to this post
    Hello Razia,

    Could you please show us the code which you are using?

    Regards,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Razia
    Razia avatar
    9 posts
    Registered:
    10 Jun 2010
    30 Jun 2010
    Link to this post
    public partial class Admin_Files : AdminPage
    {
        public override string MenuItemName
        {
            get { return "files"; }
        }
      
        public override int RightsRequired
        {
            get
            {
                return GlobalRights.ManageFiles;
            }
        }
      
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                string path = Request.QueryString.Get("path");
                path = HttpUtility.UrlDecode(path);
                if (!String.IsNullOrEmpty(path))
                {
                    fileManager.SelectedFolder = new System.IO.DirectoryInfo(MapPath("~/" + path));
                }
      
            }
        }
      
        protected override void OnPreRender(EventArgs e)
        {
            //base.OnPreRender(e);
            //if (fileManager.Mode == FileManagerMode.Upload)
            //    mainPanel.Attributes.Add("class", "wrapperUpload");
            //else
            //    mainPanel.Attributes.Add("class", "wrapperBrowser");
      
      
            base.OnPreRender(e);
            if (fileManager.Mode == FileManagerMode.Upload)
                mainPanel.Attributes.Add("class", "wrapperUpload");
            else
                mainPanel.Attributes.Add("class", "wrapperBrowser");
            var treeView = FindControlRecursive(foldersNavigation, "foldersTree") as RadTreeView;
            var radGrid = FindControlRecursive(fileManager, "fileGrid") as RadGrid;
            if (UserManager.IsCurrentUserInRole("administrators"))
            {
                RadTreeNode node = null;
                foreach (var tnode in treeView.GetAllNodes())
                {
                    if (tnode.Text == "Upload")
                    {
                        node = tnode;
                        tnode.Visible = true;
                        radGrid.ItemDataBound += new GridItemEventHandler(radGrid_ItemDataBound);
                        // radGrid.NeedDataSource += new GridNeedDataSourceEventHandler(radGrid_NeedDataSource);
      
                    }
                    else
                    {
                        tnode.Visible = false;
                    }
                }
                while (node.ParentNode != null)
                {
                    node.ParentNode.NavigateUrl = "#";
                    node = node.ParentNode;
                    node.Visible = true;
                }
            }
      
      
      
      
        }
        void radGrid_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            var radGrid = FindControlRecursive(fileManager, "fileGrid") as RadGrid;
            DataTable dt = (DataTable)radGrid.DataSource;
            DataTable dt2 = new DataTable();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (!dt.Rows[i]["Name"].Equals("Upload"))
                {
                    dt2.ImportRow(dt.Rows[i]);
                }
            }
            radGrid.DataSource = dt2;
        }
      
        void loadradgrid()
        {
            var radGrid = FindControlRecursive(fileManager, "fileGrid") as RadGrid;
            DataTable dt = (DataTable)radGrid.DataSource;
            DataTable dt2 = new DataTable();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (!dt.Rows[i]["Name"].Equals("Upload"))
                {
                    dt2.ImportRow(dt.Rows[i]);
                }
            }
            radGrid.DataSource = dt2;
            radGrid.Rebind();
        }
      
        void radGrid_ItemDataBound(object sender, GridItemEventArgs e)
        {
            //loadradgrid();
            if ((e.Item.ItemType == GridItemType.Item) || (e.Item.ItemType == GridItemType.AlternatingItem) || (e.Item.ItemType == GridItemType.EditItem))
            {
                if (e.Item is GridDataItem)
                {
                    GridDataItem dataItem = e.Item as GridDataItem;
                    if (dataItem["Name"].Text.Equals("Upload") && UserManager.IsCurrentUserInRole("administrators"))
                    {
                        dataItem.Display = true;
      
      
                    }
                    else
                    {
                        dataItem.Display = false;
                    }
      
      
                }
            }
        }
      
      
        private Control FindControlRecursive(Control root, string id)
        {
            if (root.ID == id)
            {
                return root;
            }
      
            foreach (Control c in root.Controls)
            {
                Control t = FindControlRecursive(c, id);
                if (t != null)
                {
                    return t;
                }
            }
      
            return null;
        }
      
    }

  6. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    30 Jun 2010
    Link to this post
    Hi Razia,

    Unfortunately the data source of the RadGrid cannot be changed and the paging of the grid has been calculated when the data source is created. This leaves no other options but to have the control as it is now.

    Best wishes,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
6 posts, 0 answered