コード例 #1
0
 protected void CopyFolderOnFileSystem2(FolderItem sourceFolder, FolderItem targetFolder)
 {
     PathUtil.CopyDirectory(sourceFolder.LocalDirectory.FullName, targetFolder.LocalDirectory.FullName, false);
     targetFolder.LocalDirectory.Refresh();
 }
コード例 #2
0
        private VirtualFolderInfo PerformFolderOperation(string virtualFolderPath, string destinationPath, FileOperation operation)
        {
            if (virtualFolderPath == null)
            {
                throw new ArgumentNullException("virtualFolderPath");
            }
            if (destinationPath == null)
            {
                throw new ArgumentNullException("destinationPath");
            }

            //get folder info for source and destination, thus validating the scope of both
            string absoluteSource;
            var    sourceFolder = GetFolderInfoInternal(virtualFolderPath, true, out absoluteSource);
            string absoluteDestination;

            GetFolderInfoInternal(destinationPath, false, out absoluteDestination);

            string operationName = operation == FileOperation.Move ? "move" : "copy";

            if (sourceFolder.IsRootFolder)
            {
                string msg = String.Format("Cannot {0} root folder (attempted destination: '{1}').", operationName, destinationPath);
                VfsLog.Debug(msg);
                throw new ResourceAccessException(msg);
            }

            if (String.Equals(absoluteSource, absoluteDestination, StringComparison.InvariantCultureIgnoreCase))
            {
                string msg = String.Format("Cannot {0} folder to '{1}' - source and destination are the same.", operationName, destinationPath);
                VfsLog.Debug(msg);
                throw new ResourceAccessException(msg);
            }

            var sourceDir = new DirectoryInfo(absoluteSource);

            if (sourceDir.IsParentOf(absoluteDestination))
            {
                string msg = String.Format("Cannot {0} folder '{1}' to '{2}' - destination folder is a child of the folder.", operationName, virtualFolderPath, destinationPath);
                VfsLog.Debug(msg);
                throw new ResourceAccessException(msg);
            }

            if (Directory.Exists(absoluteDestination))
            {
                string msg = "Cannot {0} folder '{1}' to '{2}' - the destination folder already exists.";
                msg = String.Format(msg, operationName, virtualFolderPath, destinationPath);
                VfsLog.Debug(msg);
                throw new ResourceOverwriteException(msg);
            }


            try
            {
                switch (operation)
                {
                case FileOperation.Move:
                    Directory.Move(absoluteSource, absoluteDestination);
                    break;

                case FileOperation.Copy:
                    PathUtil.CopyDirectory(absoluteSource, absoluteDestination, false);
                    break;

                default:
                    VfsLog.Fatal("Unsupported file operation received: {0}", operation);
                    throw new ArgumentOutOfRangeException("operation");
                }

                return(GetFolderInfo(absoluteDestination));
            }
            catch (Exception e)
            {
                string msg = String.Format("An error occurred while trying to {0} directory '{1}' to '{2}'.",
                                           operationName, virtualFolderPath, destinationPath);
                VfsLog.Warn(e, msg);
                throw new ResourceAccessException(msg, e);
            }
        }