This is a migrated thread and some comments may be shown as answers.

RadFileExplorer Explorer View is not Updating

3 Answers 121 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
Muhammad
Top achievements
Rank 1
Muhammad asked on 13 Feb 2014, 11:07 AM
I am developing the RadFileExplorer Custom Provider in order to show network files. My problem is that tree view on the left side is refreshing but on the right panel folders are not updating. I can see only the main root folders but not inside in that.

Kindly Help

3 Answers, 1 is accepted

Sort by
0
Vessy
Telerik team
answered on 18 Feb 2014, 08:58 AM
Hi Muhammad,

The described behavior could be experienced when FileExplorer cannot access the pointed viewpaths. This means the control creates root directories with the passed names, but is not able to list the folder  content.

The reason for such a behavior usually is:
  • either the viewpaths/mapping to the desired folders are not set properly
  • or the application does not have enough permissions to access the desired paths. You cans ee how to test the permissions here: Troubleshooting

In case non of the above is the case, though, we will need to examine your custom provider in order to provide any further help. A sample fully runnable project reproducing the issue will be of great help in solving the case.

Kind regards,
Veselina Raykova
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
0
Muhammad
Top achievements
Rank 1
answered on 18 Feb 2014, 10:06 AM
Thanks for your reply...

Let me give you the code, I am sure you will find the solution. I am using Rad File Explorer in SharePoint Web Part as User Control.

Following is the HTML and Code Behind Part. The Property Explorer Mode when i changed it to Default, I am facing the issue that right pane is not refreshing but when i change the property from Default to TreeView, than files will enumerate but Right Pane disappears(which makes sense) but i want the default mode with right pane refreshing. I have written a custom Provider, 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Telerik.Web.UI.Widgets;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Principal;

namespace VisualWebPartProject1.VisualWebPart1
{
    public class FileProvider : Telerik.Web.UI.Widgets.FileBrowserContentProvider
    {
        //constructor must be present when overriding a base content provider class
        //you can leave it empty
        public FileProvider(HttpContext context, string[] searchPatterns, string[] viewPaths, string[] uploadPaths, string[] deletePaths, string selectedUrl, string selectedItemTag)
            : base(context, searchPatterns, viewPaths, uploadPaths, deletePaths, selectedUrl, selectedItemTag)
        {
        }

        private void GetRecoursiveDirectory()
        {
            //directories
        }

        [DllImport("advapi32.DLL", SetLastError = true)]
        public static extern int LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);

        public override Telerik.Web.UI.Widgets.DirectoryItem ResolveRootDirectoryAsTree(string path)
        {
            try
            {
                Telerik.Web.UI.Widgets.DirectoryItem itm = null;
                //try authentication with permitted user
                string uriString = path;
                // Lesson learnt - always check for a valid URI
                //if (Uri.IsWellFormedUriString(uriString, UriKind.RelativeOrAbsolute))
                {
                    Uri uri = new Uri(uriString);
                    Console.WriteLine(uri.LocalPath);

                    string physicalPathToFolder = path;

                    IntPtr admin_token = default(IntPtr);
                    //Added these 3 lines
                    WindowsIdentity wid_current = WindowsIdentity.GetCurrent();
                    WindowsIdentity wid_admin = null;
                    WindowsImpersonationContext wic = null;

                    if (LogonUser("muhammad.ali", "ABC", "abcd@123", 9, 0, ref admin_token) != 0)
                    {
                        wid_admin = new WindowsIdentity(admin_token);
                        wic = wid_admin.Impersonate();
                        path = "\\\\10.10.2.57\\ITADmin";
                        DirectoryInfo info = new DirectoryInfo(path);

                        List<Telerik.Web.UI.Widgets.FileItem> files = new List<Telerik.Web.UI.Widgets.FileItem>();
                        try
                        {
                            foreach (FileInfo filetmp in info.GetFiles())
                                files.Add(new Telerik.Web.UI.Widgets.FileItem(filetmp.Name, filetmp.Extension, filetmp.Length, filetmp.FullName, filetmp.FullName, filetmp.FullName, Telerik.Web.UI.Widgets.PathPermissions.Delete | Telerik.Web.UI.Widgets.PathPermissions.Read | Telerik.Web.UI.Widgets.PathPermissions.Upload));
                        }
                        catch (Exception exp)
                        { }

                        List<Telerik.Web.UI.Widgets.DirectoryItem> directories = new List<Telerik.Web.UI.Widgets.DirectoryItem>();
                        foreach (DirectoryInfo dirtmp in info.GetDirectories())
                        {
                            Telerik.Web.UI.Widgets.DirectoryItem itmtmp = new Telerik.Web.UI.Widgets.DirectoryItem(dirtmp.Name, dirtmp.FullName, dirtmp.FullName, dirtmp.Name, Telerik.Web.UI.Widgets.PathPermissions.Delete | Telerik.Web.UI.Widgets.PathPermissions.Read | Telerik.Web.UI.Widgets.PathPermissions.Upload, null, null);
                            directories.Add(itmtmp);
                        }
                        itm = new Telerik.Web.UI.Widgets.DirectoryItem(path, path, path, path, Telerik.Web.UI.Widgets.PathPermissions.Read | Telerik.Web.UI.Widgets.PathPermissions.Upload | Telerik.Web.UI.Widgets.PathPermissions.Delete, files.ToArray(), directories.ToArray());

                    }
                }
                //return null;
                //throw new NotImplementedException();
                return itm;
            }
            catch (Exception exp)
            {
                return null;
            }
        }

        public override Telerik.Web.UI.Widgets.DirectoryItem ResolveDirectory(string path)
        {
            //try authentication with permitted user
            try
            {
                Telerik.Web.UI.Widgets.DirectoryItem itm = null;
                //string uriString = @"//10.10.2.57/ITADmin";
                string uriString = path;
                // Lesson learnt - always check for a valid URI
                //if (Uri.IsWellFormedUriString(uriString, UriKind.RelativeOrAbsolute))
                {
                    Uri uri = new Uri(uriString);
                    Console.WriteLine(uri.LocalPath);

                    string physicalPathToFolder = path;

                    IntPtr admin_token = default(IntPtr);
                    //Added these 3 lines
                    WindowsIdentity wid_current = WindowsIdentity.GetCurrent();
                    WindowsIdentity wid_admin = null;
                    WindowsImpersonationContext wic = null;

                    if (LogonUser("muhammad.ali", "ABC", "abcd@123", 9, 0, ref admin_token) != 0)
                    {
                        wid_admin = new WindowsIdentity(admin_token);
                        wic = wid_admin.Impersonate();

                        DirectoryInfo info = new DirectoryInfo(path);

                        List<Telerik.Web.UI.Widgets.FileItem> files = new List<Telerik.Web.UI.Widgets.FileItem>();
                        foreach (FileInfo filetmp in info.GetFiles())
                            files.Add(new Telerik.Web.UI.Widgets.FileItem(filetmp.Name, filetmp.Extension, filetmp.Length, filetmp.FullName, filetmp.FullName, filetmp.FullName, Telerik.Web.UI.Widgets.PathPermissions.Delete | Telerik.Web.UI.Widgets.PathPermissions.Read | Telerik.Web.UI.Widgets.PathPermissions.Upload));

                        List<Telerik.Web.UI.Widgets.DirectoryItem> directories = new List<Telerik.Web.UI.Widgets.DirectoryItem>();
                        foreach (DirectoryInfo dirtmp in info.GetDirectories())
                            directories.Add(new Telerik.Web.UI.Widgets.DirectoryItem(dirtmp.Name, dirtmp.FullName, dirtmp.FullName, dirtmp.FullName, Telerik.Web.UI.Widgets.PathPermissions.Delete | Telerik.Web.UI.Widgets.PathPermissions.Read | Telerik.Web.UI.Widgets.PathPermissions.Upload, null, null));

                        itm = new Telerik.Web.UI.Widgets.DirectoryItem(path, path, path, path, Telerik.Web.UI.Widgets.PathPermissions.Read | Telerik.Web.UI.Widgets.PathPermissions.Upload | Telerik.Web.UI.Widgets.PathPermissions.Delete, files.ToArray(), directories.ToArray());
                    }
                }
                return itm;
            }
            catch (Exception exp)
            {
                return null;
            }

            //return null;
            //return base.ResolveDirectory(path);
            //throw new NotImplementedException();
        }

        public override FileItem GetFileItem(string path)
        {
            //try authentication with permitted user
            FileItem tim = null;
            try
            {
                Telerik.Web.UI.Widgets.DirectoryItem itm = null;
                string uriString = path;
                // Lesson learnt - always check for a valid URI
               // if (Uri.IsWellFormedUriString(uriString, UriKind.RelativeOrAbsolute))
                {
                    Uri uri = new Uri(uriString);
                    Console.WriteLine(uri.LocalPath);

                    string physicalPathToFolder = path;

                    IntPtr admin_token = default(IntPtr);
                    //Added these 3 lines
                    WindowsIdentity wid_current = WindowsIdentity.GetCurrent();
                    WindowsIdentity wid_admin = null;
                    WindowsImpersonationContext wic = null;

                    if (LogonUser("muhammad.ali", "ABC", "abcd@123", 9, 0, ref admin_token) != 0)
                    {
                        wid_admin = new WindowsIdentity(admin_token);
                        wic = wid_admin.Impersonate();
                        if (File.Exists(path))
                        {
                            FileInfo file = new FileInfo(path);
                            tim = new FileItem(file.Name, file.Extension, file.Length, "", file.FullName, "", PathPermissions.Delete | PathPermissions.Read | PathPermissions.Upload);
                            
                        }
                    }
                }
                return tim;
            }
            catch (Exception exp)
            {
                return null;
            }     
        }
        public override string GetFileName(string url)
        {
            //return null;
            throw new NotImplementedException();
        }
        public override string GetPath(string url)
        {
            throw new NotImplementedException();
        }
        public override System.IO.Stream GetFile(string url)
        {
            throw new NotImplementedException();
        }
        public override string StoreBitmap(System.Drawing.Bitmap bitmap, string url, System.Drawing.Imaging.ImageFormat format)
        {
            throw new NotImplementedException();
        }
        public override string StoreFile(Telerik.Web.UI.UploadedFile file, string path, string name, params string[] arguments)
        {
            throw new NotImplementedException();
        }
        public override string DeleteFile(string path)
        {
            throw new NotImplementedException();
        }
        public override string DeleteDirectory(string path)
        {
            throw new NotImplementedException();
        }
        public override string CreateDirectory(string path, string name)
        {
            throw new NotImplementedException();
        }
        public override string MoveFile(string path, string newPath)
        {
            return base.MoveFile(path, newPath);
        }
        public override string MoveDirectory(string path, string newPath)
        {
            return base.MoveDirectory(path, newPath);
        }
        public override string CopyFile(string path, string newPath)
        {
            return base.CopyFile(path, newPath);
        }
        public override string CopyDirectory(string path, string newPath)
        {
            return base.CopyDirectory(path, newPath);
        }
        public override DirectoryItem[] ResolveRootDirectoryAsList(string path)
        {
            //try authentication with permitted user
            try
            {
                Telerik.Web.UI.Widgets.DirectoryItem itm = null;
                List<DirectoryItem> listitm = new List<DirectoryItem>();
                string uriString = path;
                // Lesson learnt - always check for a valid URI
                //if (Uri.IsWellFormedUriString(uriString, UriKind.RelativeOrAbsolute))
                {
                    Uri uri = new Uri(uriString);
                    Console.WriteLine(uri.LocalPath);

                    string physicalPathToFolder =path;

                    IntPtr admin_token = default(IntPtr);
                    //Added these 3 lines
                    WindowsIdentity wid_current = WindowsIdentity.GetCurrent();
                    WindowsIdentity wid_admin = null;
                    WindowsImpersonationContext wic = null;

                    if (LogonUser("muhammad.ali", "ABC", "abcd@123", 9, 0, ref admin_token) != 0)
                    {
                        wid_admin = new WindowsIdentity(admin_token);
                        wic = wid_admin.Impersonate();

                        DirectoryInfo info = new DirectoryInfo(path);


                        List<Telerik.Web.UI.Widgets.FileItem> files = new List<Telerik.Web.UI.Widgets.FileItem>();
                        foreach (FileInfo filetmp in info.GetFiles())
                            files.Add(new Telerik.Web.UI.Widgets.FileItem(filetmp.Name, filetmp.Extension, filetmp.Length, filetmp.FullName, filetmp.FullName, filetmp.FullName, Telerik.Web.UI.Widgets.PathPermissions.Delete | Telerik.Web.UI.Widgets.PathPermissions.Read | Telerik.Web.UI.Widgets.PathPermissions.Upload));

                        List<Telerik.Web.UI.Widgets.DirectoryItem> directories = new List<Telerik.Web.UI.Widgets.DirectoryItem>();
                        foreach (DirectoryInfo dirtmp in info.GetDirectories())
                            directories.Add(new Telerik.Web.UI.Widgets.DirectoryItem(dirtmp.Name, dirtmp.FullName, dirtmp.FullName, dirtmp.FullName, Telerik.Web.UI.Widgets.PathPermissions.Delete | Telerik.Web.UI.Widgets.PathPermissions.Read | Telerik.Web.UI.Widgets.PathPermissions.Upload, null, null));

                        itm = new Telerik.Web.UI.Widgets.DirectoryItem(path, path, path, path, Telerik.Web.UI.Widgets.PathPermissions.Read | Telerik.Web.UI.Widgets.PathPermissions.Upload | Telerik.Web.UI.Widgets.PathPermissions.Delete, files.ToArray(), directories.ToArray());
                        listitm.Add(itm);
                    }
                }
                return listitm.ToArray();
            }
            catch (Exception exp)
            {
                return null;
            }
        }

        // ##############################################################################
        // !!! IMPORTANT !!!
        // The compilator will not complain if these methods are not overridden, but it is highly recommended to override them

        public override bool CheckDeletePermissions(string folderPath)
        {
            return base.CheckDeletePermissions(folderPath);
        }
        public override bool CheckWritePermissions(string folderPath)
        {
            return base.CheckWritePermissions(folderPath);
        }

        //Introduced in the 2010.2.826 version of the control
        public override bool CheckReadPermissions(string folderPath)
        {
            return base.CheckReadPermissions(folderPath);
        }
        // ##############################################################################

    }
 
}


<telerik:RadFileExplorer runat="server" ID="RadFileExplorer1" Width="100%" Height="350px"
                OnClientFolderChange="OnClientFolderChange" CssClass="rfeFocus" AllowPaging="true" PageSize="10" 
                ExplorerMode="Default"  DisplayUpFolderItem="True" Enabled="true" EnableEmbeddedScripts="true" EnableOpenFile="true" RenderMode="Classic"  >
                <Configuration EnableAsyncUpload="true" AllowMultipleSelection="true" ContentProviderTypeName="FileProvider"></Configuration>
            </telerik:RadFileExplorer>





0
Vessy
Telerik team
answered on 20 Feb 2014, 04:35 PM
Hi Muhammad,

The latest moment of the page life-cycle when the paths of FileExplorer (ViewPaths/UploadPaths/DeletePAths) can be configured is the Page_Load event. Could you verify that you are not setting them later than that?

The other thing that you should pay attention is that when working with impersonation, you have to also make sure that used handlers has proper permissions. If you are using a general handler with your content provider (like the one provided by us in this help article) you have to make sure that is is is added to the <location> section of the web.config. In this way the handler will be excluded from the authentication rules and all requests to it will have the correct permissions. The same thing applies to the Telerik.Web.UI.WebResource.axd handler:
<location path="FileSystemHandler.ashx" allowOverride="true">
    <system.web>
       <authorization>
            <allow roles="*"/>
        </authorization>
    </system.web>
</location>
<location path="Telerik.Web.UI.WebResource.axd" allowOverride="true">
   <system.web>
     <identity impersonate="true" userName="HostingServer\userName" password="userPassword"/>
     <authorization>
       <allow users="*"/>
     </authorization>
   </system.web>
 </location>

If non of the above helps in solving the case, though, we will need to run a sample project and debug it locally and provide any further assistance.

Regards,
Veselina Raykova
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
Tags
FileExplorer
Asked by
Muhammad
Top achievements
Rank 1
Answers by
Vessy
Telerik team
Muhammad
Top achievements
Rank 1
Share this question
or