public override string CreateDirectory(string virtualTargetPath, string name)
    {
        string physicalTargetPath = this.GetPhysicalFromVirtualPath(virtualTargetPath);

        if (physicalTargetPath == null)
        {
            return(string.Format("The virtual path: '{0}' cannot be converted to a physical path", virtualTargetPath));
        }

        string virtualNewFolderPath  = PathHelper.AddEndingSlash(virtualTargetPath, '/') + name;
        string physicalNewFolderPath = this.GetPhysicalFromVirtualPath(virtualNewFolderPath);

        if (physicalNewFolderPath == null)
        {
            return(string.Format("The virtual path: '{0}'  cannot be converted to a physical path", virtualNewFolderPath));
        }

        if (Directory.Exists(physicalNewFolderPath))
        {
            string error = string.Format("The directory: '{0}' already exists", virtualNewFolderPath);;
            return(error);
        }

        // There is no restriction with the FileExplorer's permissions ==> Create can be performed
        // but there can be some FileSystems restrictions
        string errorMessage = FileSystem.CreateDirectory(physicalTargetPath, name, virtualTargetPath);

        return(errorMessage);
    }
    /// <summary>
    /// Gets the folders that are contained in a specific virtual directory
    /// </summary>
    /// <param name="virtualPath">The virtual directory that contains the folders</param>
    /// <returns>Array of 'DirectoryItem'</returns>
    private DirectoryItem[] GetDirectories(string virtualPath)
    {
        List <DirectoryItem> directoryItems = new List <DirectoryItem>();
        string physicalPath = this.GetPhysicalFromVirtualPath(virtualPath);

        if (physicalPath == null)
        {
            return(null);
        }
        string[] directories;

        try
        {
            directories = Directory.GetDirectories(physicalPath);            // Can throw an exeption ;
            foreach (string dirPath in directories)
            {
                DirectoryInfo dirInfo        = new DirectoryInfo(dirPath);
                string        newVirtualPath = PathHelper.AddEndingSlash(virtualPath, '/') + PathHelper.GetDirectoryName(dirPath) + "/";
                DirectoryItem dirItem        = new DirectoryItem(PathHelper.GetDirectoryName(dirPath),
                                                                 string.Empty,
                                                                 newVirtualPath,
                                                                 PathHelper.AddEndingSlash(virtualPath, '/'),
                                                                 GetPermissions(dirPath),
                                                                 GetFiles(virtualPath),
                                                                 null
                                                                 );
                directoryItems.Add(dirItem);
            }
        }
        catch (IOException)
        {        // The parent directory is moved or deleted
        }

        return(directoryItems.ToArray());
    }
コード例 #3
0
    public static string CreateDirectory(string physicalTargetPath, string directoryName, string virtualTargetPath)
    {
        try
        {
            DirectoryInfo parentDir = new DirectoryInfo(physicalTargetPath);

            Directory.CreateDirectory(PathHelper.AddEndingSlash(physicalTargetPath, '\\') + directoryName, parentDir.GetAccessControl());
        }
        catch (DirectoryNotFoundException)
        {
            string message = string.Format("FileSystem restriction: Directory with name '{0}' is not found!", virtualTargetPath);
            return(message);
        }
        catch (UnauthorizedAccessException)
        {
            string message = "FileSystem's restriction: You do not have enough permissions for this operation!";
            return(message);
        }
        catch (IOException)
        {
            string message = string.Format("FileSystem restriction: The directory '{0}' cannot be created!", virtualTargetPath);
            return(message);
        }

        return(string.Empty);
    }
    public override DirectoryItem ResolveRootDirectoryAsTree(string path)
    {
        string physicalPath;
        string virtualPath = string.Empty;

        if (PathHelper.IsSharedPath(path) || PathHelper.IsPhysicalPath(path))
        {        // The path is a physical path
            physicalPath = path;

            foreach (KeyValuePair <string, string> mappedPath in MappedPaths)
            {
                // Checks whether a mapping exists for the current physical path
                // 'mappedPath.Value' does not end with trailing slash. It looks like : "C:\Path\Dir"
                if (physicalPath.StartsWith(mappedPath.Value, StringComparison.CurrentCultureIgnoreCase))
                {                // Exists
                    // Get the part of the physical path which does not contain the mappeed part
                    string restOfPhysicalPath = physicalPath.Substring(mappedPath.Value.Length);

                    // 'mappedPath.Value' does not end with '\'
                    // // The 'restOfVirtualPath' is something like Folder_1/SubFolder_2/ ==> convert it to Folder_1\SubFolder_2\
                    virtualPath = mappedPath.Key + restOfPhysicalPath.Replace('\\', '/');


                    virtualPath = PathHelper.AddEndingSlash(virtualPath, '/');
                    break;                    // Exit the 'foreach' loop ;
                }
            }
        }
        else
        {        // Virtual path ;
            virtualPath  = PathHelper.AddEndingSlash(path, '/');
            physicalPath = this.GetPhysicalFromVirtualPath(path);
            if (physicalPath == null)
            {
                return(null);
            }
        }

        DirectoryItem result = new DirectoryItem(PathHelper.GetDirectoryName(physicalPath),
                                                 string.Empty,
                                                 virtualPath,
                                                 string.Empty,
                                                 GetPermissions(physicalPath),
                                                 new FileItem[] { },                                                        // Files are added in the ResolveDirectory method
                                                 GetDirectories(virtualPath)
                                                 );

        return(result);
    }
    public override string StoreFile(Telerik.Web.UI.UploadedFile file, string path, string name, params string[] arguments)
    {
        string physicalPath = this.GetPhysicalFromVirtualPath(path);

        if (physicalPath == null)
        {
            return(string.Empty);
        }

        physicalPath = PathHelper.AddEndingSlash(physicalPath, '\\') + name;
        file.SaveAs(physicalPath);


        // Returns the path to the newly created file
        return(PathHelper.AddEndingSlash(path, '/') + name);
    }
    public override string MoveDirectory(string virtualSourcePath, string virtualDestPath)
    {
        virtualSourcePath = PathHelper.AddEndingSlash(virtualSourcePath, '/');
        virtualDestPath   = PathHelper.AddEndingSlash(virtualDestPath, '/');

        string physicalSourcePath;

        physicalSourcePath = this.GetPhysicalFromVirtualPath(virtualSourcePath);
        if (physicalSourcePath == null)
        {
            return(string.Format("The virtual path :'{0}' cannot be converted to a physical path", virtualSourcePath));
        }

        string physicalDestinationPath;

        physicalDestinationPath = this.GetPhysicalFromVirtualPath(virtualDestPath);
        if (physicalDestinationPath == null)
        {
            return(string.Format("The virtual path :'{0}' cannot be converted to a physical path", virtualDestPath));
        }

        string newFolderName = physicalDestinationPath;

        // Checks whether the folder already exists in the destination folder ;
        if (Directory.Exists(newFolderName))
        {        // Yes the folder exists :
            string message = string.Format("The folder '{0}' already exists", virtualDestPath);
            return(message);
        }

        // Checks whether the source directory is parent of the destination directory ;
        if (PathHelper.IsParentOf(virtualSourcePath, virtualDestPath))
        {
            string message = string.Format("The folder  '{0}' is parent of the '{1}' directory. Operation is canceled!", virtualSourcePath, virtualDestPath);
            return(message);
        }

        // There is not a permission issue with the FileExplorer's permissions ==> Move can be performed
        // But, there can be some FileSystem permissions issue (file system's read/write permissions) ;
        string errorMessage = FileSystem.MoveDirectorty(physicalSourcePath, physicalDestinationPath, virtualSourcePath, virtualDestPath);

        return(errorMessage);
    }
コード例 #7
0
    public override string StoreFile(Telerik.Web.UI.UploadedFile file, string path, string name, params string[] arguments)
    {
        string physicalPath = this.GetPhysicalFromVirtualPath(path);

        if (physicalPath == null)
        {
            return(string.Empty);
        }

        physicalPath = PathHelper.AddEndingSlash(physicalPath, '\\') + name;
        var ffile = new System.IO.FileInfo(physicalPath);

        if (ffile.Directory != null && !ffile.Directory.Exists)
        {
            ffile.Directory.Create();
        }
        file.SaveAs(physicalPath);


        // Returns the path to the newly created file
        return(PathHelper.AddEndingSlash(path, '/') + name);
    }
コード例 #8
0
    public static string CopyDirectory(string physycalSourcePath, string physicalDestPath, string virtualSourcePath, string virtualDestPath)
    {
        // Copy all files ;
        string        newDirPhysicalFullPath; // Contains the physical path to the new directory ;
        DirectoryInfo dirInfoSource;

        try
        {
            dirInfoSource          = new DirectoryInfo(physycalSourcePath);
            newDirPhysicalFullPath = string.Format("{0}{1}{2}", PathHelper.AddEndingSlash(physicalDestPath, '\\'), dirInfoSource.Name, "\\");

            // Else ;
            Directory.CreateDirectory(newDirPhysicalFullPath, dirInfoSource.GetAccessControl());
        }
        catch (UnauthorizedAccessException ex)
        {
            string message = "FileSystem's restriction: You do not have enough permissions for this operation!";
            return(message);
        }

        // Directory is created ;

        foreach (string currentFilePath in Directory.GetFiles(physycalSourcePath))
        {
            FileInfo fileInfo = new FileInfo(currentFilePath);

            string newFilePath = newDirPhysicalFullPath + fileInfo.Name;

            try
            {
                File.Copy(currentFilePath, newFilePath);
            }

            catch (FileNotFoundException ex)
            {
                string message = string.Format("File: '{0}' does not exist!", virtualSourcePath);
                return(message);
            }
            catch (UnauthorizedAccessException ex)
            {
                string message = "You do not have enough permissions for this operation!";
                return(message);
            }
            catch (IOException ex)
            {
                string message = "The operation cannot be compleated";
                return(message);
            }
        }

        // Copy all subdirectories ;
        foreach (string physicalCurrentSourcePath in Directory.GetDirectories(physycalSourcePath))
        {
            DirectoryInfo dirInfo = new DirectoryInfo(physicalCurrentSourcePath);
            string        physicalCurrentDestPath  = newDirPhysicalFullPath;    // Change the name of the variable ;
            string        virtualCurrentSourcePath = string.Format("{0}{1}{2}", PathHelper.AddEndingSlash(virtualSourcePath, '/'), dirInfo.Name, "/");
            string        virtualCurrentDestPath   = string.Format("{0}{1}{2}", PathHelper.AddEndingSlash(virtualDestPath, '/'), dirInfoSource.Name, "/");

            // Call recursively the Directory copy function ;
            string returnedError = CopyDirectory(physicalCurrentSourcePath, physicalCurrentDestPath, virtualCurrentSourcePath, virtualCurrentDestPath);
            if (returnedError != string.Empty)
            {            // An error occured ;
                return(returnedError);
            }
        }

        // No errors.
        return(string.Empty);
    }