示例#1
0
        /// <summary>
        /// Initialize new instance of class ElFinder.FileSystemDriver
        /// </summary>
        public WebDavDriver(string server, Guid token)
        {
            this.roots = new List <WebDavRoot>();
            //client = new WebDavClient(server, login, password);
            client = new WebDavClient(server, token);
            if (client == null)
            {
                throw new ElFinderException("Произошла ошибка при инициализации WebDav.");
            }
            if (!String.IsNullOrEmpty(client.LastError))
            {
                throw new ElFinderException("Произошла ошибка при инициализации WebDav" + client.LastError);
            }
            clientRootDirInfo = client.GetInfo("");

            if (clientRootDirInfo == null || token == Guid.Empty)
            {
                throw new ElFinderException("Произошла ошибка при инициализации WebDav. Нет доступа к корневой директории.");
            }

            this.AddRootFolder(Recived);
            this.AddRootFolder(Upload);
            this.token = token;
        }
示例#2
0
        private string GetCorrectDestinationFileName(string targetDecrypted)
        {
            DirInfo targetInfo = client.GetInfo(targetDecrypted);
            string  destinationFileName, ext = "", path = "", nameWithoutExt = "";

            if (targetInfo.IsDirectory && targetDecrypted.EndsWith("/"))
            {
                destinationFileName = targetDecrypted.Substring(0, targetDecrypted.Length - 1) + " (1)";
            }
            else
            {
                path                = targetDecrypted.Replace(targetInfo.DisplayName, "");
                ext                 = Path.GetExtension(targetInfo.DisplayName);
                nameWithoutExt      = !string.IsNullOrEmpty(ext) ? targetInfo.DisplayName.Replace(ext, "") : targetInfo.DisplayName;
                destinationFileName = string.Format("{0}{1} (1){2}", path, nameWithoutExt, ext);
            }

            DirInfo newDestInfo = client.GetInfo(destinationFileName);
            int     i           = 2;

            while (newDestInfo != null)
            {
                if (targetInfo.IsDirectory && targetDecrypted.EndsWith("/"))
                {
                    destinationFileName = string.Format("{0} ({1})", targetDecrypted.Substring(0, targetDecrypted.Length - 1), i);
                }
                else
                {
                    destinationFileName = string.Format("{0}{1} ({3}){2}", path, nameWithoutExt, ext, i);
                }

                newDestInfo = client.GetInfo(destinationFileName);
                i++;
            }

            return(destinationFileName);
        }