private void OnItemRenaming(RenameCancelEventArgs e)
 {
     if (ItemRenaming != null)
     {
         ItemRenaming(this, e);
     }
 }
Example #2
0
 void controller_ItemRenaming(object sender, RenameCancelEventArgs e)
 {
     if (ItemRenaming != null)
     {
         ItemRenaming(this, e);
     }
 }
        private string ProcessRename(FileManagerItemInfo fileManagerItemInfo, string newName)
        {
            RenameCancelEventArgs cancelArg = new RenameCancelEventArgs();
            cancelArg.FileManagerItem = fileManagerItemInfo;
            cancelArg.NewName = newName;
            OnItemRenaming(cancelArg);
            if (cancelArg.Cancel)
            {
                return ClientMessageEventReference(cancelArg.ClientMessage);
            }

            if (cancelArg.NewName == null || cancelArg.NewName.Length == 0 || cancelArg.NewName.StartsWith("."))
            {
                return ClientMessageEventReference(GetResourceString("MustTypeFileName", "You must type a file name."));
            }

            if (!Validate(cancelArg.NewName))
            {
                return ClientMessageEventReference(GetResourceString("NotAllowedCharacters", "A file name cannot contain any of the following characters: \\/:*?\"<>|"));
            }

            if (fileManagerItemInfo.File.Exists)
            {
                string newFileExt = Path.GetExtension(cancelArg.NewName).ToLower(CultureInfo.InvariantCulture).TrimStart('.');
                if (newFileExt.Length == 0 ||
                    HiddenFilesArray.Contains(newFileExt) ||
                    ProhibitedFilesArray.Contains(newFileExt))
                    cancelArg.NewName += fileManagerItemInfo.File.Extension;
            }

            FileManagerItemInfo renamedItem = ResolveFileManagerItemInfo(fileManagerItemInfo.FileManagerPath.Substring(0, fileManagerItemInfo.FileManagerPath.LastIndexOf('/')) + "/" + cancelArg.NewName);
            if (renamedItem.Directory.Exists || renamedItem.File.Exists)
            {
                string fileExistsMessage = GetResourceString("CannotRenameFile", "Cannot rename file: A file with the name you specified already exists. Specify a different file name.");
                return ClientMessageEventReference(fileExistsMessage);
            }

            bool b = false;
            if (fileManagerItemInfo.Directory.Exists)
            {
                b = true;
                fileManagerItemInfo.Directory.MoveTo(renamedItem.PhysicalPath);
            }
            else if (fileManagerItemInfo.File.Exists)
            {
                fileManagerItemInfo.File.MoveTo(renamedItem.PhysicalPath);
            }

            RenameEventArgs arg = new RenameEventArgs();
            arg.FileManagerItem = renamedItem;
            OnItemRenamed(arg);

            StringBuilder sb = new StringBuilder();
            if (b)
                AddFolderTreeRefreshEventReference(sb, _callbackControl.CurrentDirectory);
            sb.AppendLine(ClientRefreshEventReference);
            return sb.ToString();
        }
 private void OnItemRenaming(RenameCancelEventArgs e)
 {
     if (ItemRenaming != null)
         ItemRenaming (this, e);
 }
 void controller_ItemRenaming(object sender, RenameCancelEventArgs e)
 {
     if (ItemRenaming != null)
         ItemRenaming(this, e);
 }