FileBrowserContentProvider for accessing network folder problem

3 posts, 0 answers
  1. Rosanna
    Rosanna avatar
    2 posts
    Member since:
    Apr 2013

    Posted 08 Jul 2013 Link to this post

    Hi all,
    I'm trying to develope my own FileBrowserContentProvider for accessing network folder ("\\NetFolderName\\disk1\\folldername..."), but I found a problem: treelist on left works correct and shows the right structure of folder, but when I try to browse one of this element the filelist on right does't refresh, ant still show the root folder elements (it will refresh with the uploadpanel but does't change the content).
    Any helps? Thanks...

    Here the example code: FileProvider class
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Web;
    using Telerik.Web.UI.Widgets;
     
    namespace Cep.Print
    {
     
     
        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
            }
     
            public override Telerik.Web.UI.Widgets.DirectoryItem ResolveRootDirectoryAsTree(string path)
            {
                //try authentication with permitted user
                #region Login
                //CONTROLLO CHE SIA DA EFFETTUARE IL LOGIN UTENTE
                string LoginDaEffettuare = System.Configuration.ConfigurationManager.AppSettings["EffettuaLoginUtente"].ToString();
                bool bLogin = false;
                if (!String.IsNullOrEmpty(LoginDaEffettuare))
                    if (LoginDaEffettuare.CompareTo("1") == 0)
                        bLogin = true;
     
                //EFFETTUO IL LOGIN UTENTE SE NECESSARIO
                CEP.Authorization.SpecialAuthentication Special = new CEP.Authorization.SpecialAuthentication();
                if (bLogin)
                {
                    string userName = System.Configuration.ConfigurationManager.AppSettings["NomeUtente"].ToString();
                    string domain = System.Configuration.ConfigurationManager.AppSettings["Dominio"].ToString();
                    string password = System.Configuration.ConfigurationManager.AppSettings["Psw"].ToString();
                    if (!Special.impersonateValidUser(userName, domain, password))
                    {
                        String errore = "PERMESSO DI ACCESSO AL DOMINIO " + domain + " NEGATO!";
                        return null;
                    }
                }
                else
                {
                }
     
                #endregion
                 
                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())
                {
     
     
                     
     
                    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);
                }
                Telerik.Web.UI.Widgets.DirectoryItem 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;
     
                //return null;
                //throw new NotImplementedException();
            }
             
     
            public override Telerik.Web.UI.Widgets.DirectoryItem ResolveDirectory(string path)
            {
                //try authentication with permitted user
                #region Login
                //CONTROLLO CHE SIA DA EFFETTUARE IL LOGIN UTENTE
                string LoginDaEffettuare = System.Configuration.ConfigurationManager.AppSettings["EffettuaLoginUtente"].ToString();
                bool bLogin = false;
                if (!String.IsNullOrEmpty(LoginDaEffettuare))
                    if (LoginDaEffettuare.CompareTo("1") == 0)
                        bLogin = true;
     
                //EFFETTUO IL LOGIN UTENTE SE NECESSARIO
                CEP.Authorization.SpecialAuthentication Special = new CEP.Authorization.SpecialAuthentication();
                if (bLogin)
                {
                    string userName = System.Configuration.ConfigurationManager.AppSettings["NomeUtente"].ToString();
                    string domain = System.Configuration.ConfigurationManager.AppSettings["Dominio"].ToString();
                    string password = System.Configuration.ConfigurationManager.AppSettings["Psw"].ToString();
                    if (!Special.impersonateValidUser(userName, domain, password))
                    {
                        String errore = "PERMESSO DI ACCESSO AL DOMINIO " + domain + " NEGATO!";
                        return null;
                    }
                }
                else
                {
                }
     
                #endregion
     
                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));
     
                Telerik.Web.UI.Widgets.DirectoryItem 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;
     
                //return null;
                //return base.ResolveDirectory(path);
                //throw new NotImplementedException();
            }
     
     
            public override FileItem GetFileItem(string path)
            {
                //try authentication with permitted user
                #region Login
                //CONTROLLO CHE SIA DA EFFETTUARE IL LOGIN UTENTE
                string LoginDaEffettuare = System.Configuration.ConfigurationManager.AppSettings["EffettuaLoginUtente"].ToString();
                bool bLogin = false;
                if (!String.IsNullOrEmpty(LoginDaEffettuare))
                    if (LoginDaEffettuare.CompareTo("1") == 0)
                        bLogin = true;
     
                //EFFETTUO IL LOGIN UTENTE SE NECESSARIO
                CEP.Authorization.SpecialAuthentication Special = new CEP.Authorization.SpecialAuthentication();
                if (bLogin)
                {
                    string userName = System.Configuration.ConfigurationManager.AppSettings["NomeUtente"].ToString();
                    string domain = System.Configuration.ConfigurationManager.AppSettings["Dominio"].ToString();
                    string password = System.Configuration.ConfigurationManager.AppSettings["Psw"].ToString();
                    if (!Special.impersonateValidUser(userName, domain, password))
                    {
                        String errore = "PERMESSO DI ACCESSO AL DOMINIO " + domain + " NEGATO!";
                        return null;
                    }
                }
                else
                {
                }
     
                #endregion
                if (File.Exists(path))
                {
     
     
                    FileInfo file = new FileInfo(path);
                    FileItem tim = new FileItem(file.Name, file.Extension, file.Length, "", file.FullName, "", PathPermissions.Delete | PathPermissions.Read | PathPermissions.Upload);
                    return tim;
                }
                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
                #region Login
                //CONTROLLO CHE SIA DA EFFETTUARE IL LOGIN UTENTE
                string LoginDaEffettuare = System.Configuration.ConfigurationManager.AppSettings["EffettuaLoginUtente"].ToString();
                bool bLogin = false;
                if (!String.IsNullOrEmpty(LoginDaEffettuare))
                    if (LoginDaEffettuare.CompareTo("1") == 0)
                        bLogin = true;
     
                //EFFETTUO IL LOGIN UTENTE SE NECESSARIO
                CEP.Authorization.SpecialAuthentication Special = new CEP.Authorization.SpecialAuthentication();
                if (bLogin)
                {
                    string userName = System.Configuration.ConfigurationManager.AppSettings["NomeUtente"].ToString();
                    string domain = System.Configuration.ConfigurationManager.AppSettings["Dominio"].ToString();
                    string password = System.Configuration.ConfigurationManager.AppSettings["Psw"].ToString();
                    if (!Special.impersonateValidUser(userName, domain, password))
                    {
                        String errore = "PERMESSO DI ACCESSO AL DOMINIO " + domain + " NEGATO!";
                        return null;
                    }
                }
                else
                {
                }
     
                #endregion
     
                List<DirectoryItem> listitm = new List<DirectoryItem>();
                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));
     
                Telerik.Web.UI.Widgets.DirectoryItem 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();
      
            }
     
     
            // ##############################################################################
            // !!! 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);
            }
            // ##############################################################################
     
        }
     
    }

    WebForm containing FileExplorer c# part:
      public partial class WebForm2 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    FileExplorer1.Configuration.ContentProviderTypeName = typeof(FileProvider).AssemblyQualifiedName;
                     
      
                    string PercorsoTerminal = System.Configuration.ConfigurationManager.AppSettings["PathStampeTerminal"].ToString();
                    String consulente = (String)Session[Const.SessionCodiceConsulente];
                    PercorsoTerminal = PercorsoTerminal + "\\" + consulente + "\\SIOGERE";
                    string initialPath = PercorsoTerminal;
                    FileExplorer1.Configuration.SearchPatterns = new string[] { "*.*" };
     
     
     
     
                    FileExplorer1.Configuration.ViewPaths = new String[] { initialPath };
                    FileExplorer1.Configuration.UploadPaths = new String[] { initialPath };
                    FileExplorer1.Configuration.DeletePaths = new String[] { initialPath };
     
     
                }
     
                 
            }
    }

    webform aspx part:
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
        <div>
            <div class="leftPane" style="width: 1000px;">
                <telerik:RadFileExplorer runat="server" ID="FileExplorer1" Width="100%" Height="350px" OnClientFolderChange=""
                    CssClass="rfeFocus" AllowPaging="true" PageSize="10" ExplorerMode="Default" DisplayUpFolderItem="True" EnableAsyncUpload="True" EnableCopy="True" >
                    <Configuration EnableAsyncUpload="true" AllowMultipleSelection="true"></Configuration>
                </telerik:RadFileExplorer>
            </div>
            <div style="float: left;">
                <fieldset style="width: 230px; height: 220px">
                    <legend>Preview</legend>
                </fieldset>
            </div>
        </div>
    </asp:Content>

  2. Rosanna
    Rosanna avatar
    2 posts
    Member since:
    Apr 2013

    Posted 09 Jul 2013 Link to this post

    It was a permission problem, solved!
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Muhammad
    Muhammad avatar
    3 posts
    Member since:
    Apr 2013

    Posted 12 Feb 2014 in reply to Rosanna Link to this post

    I am facing the exact problem, My File Explorer Right Pane is not refreshing, How did you do that in order to resolve the issue, Kindly Share... I know that you wrote it is a permission issue but how to resolve , the same impersonation code is running for Tree View.. Kindly Help
Back to Top