示例#1
0
        public String PasteClipboard(WorkBox workBox, String folderPath)
        {
            Dictionary <String, List <int> > clipboardItems = new Dictionary <String, List <int> >();
            UserProfile userProfile = GetUserProfile(workBox.Site);

            String clipboardAction = "";

            try
            {
                clipboardAction = GetClipboard(userProfile, clipboardItems);

                SPFolder folder = workBox.DocumentLibrary.RootFolder;
                WBLogging.Generic.Unexpected("Folder path: ##" + folderPath + "##");
                if (folder == null)
                {
                    WBLogging.Generic.Unexpected("folder is null !!!");
                }

                folderPath = folderPath.WBxTrim();
                if (!String.IsNullOrEmpty(folderPath))
                {
                    folder = folder.WBxGetFolderPath(folderPath);
                }

                bool allowUnsafeUpdatesOriginalValue = workBox.Web.AllowUnsafeUpdates;
                workBox.Web.AllowUnsafeUpdates = true;

                foreach (String workBoxURL in clipboardItems.Keys)
                {
                    List <int> ids = clipboardItems[workBoxURL];

                    using (WorkBox clipboardWorkBox = new WorkBox(workBoxURL))
                    {
                        clipboardWorkBox.Web.AllowUnsafeUpdates = true;

                        SPDocumentLibrary documents = clipboardWorkBox.DocumentLibrary;

                        foreach (int id in ids)
                        {
                            SPListItem item = documents.GetItemById(id);

                            bool cutOriginal = (clipboardAction == WBUser.CLIPBOARD_ACTION__CUT);

                            try
                            {
                                WBUtils.CutOrCopyIntoFolder(workBox.Web, folder, item, cutOriginal);
                            }
                            catch (Exception docLevelException)
                            {
                                WBUtils.SendErrorReport(workBox.Web, "Error pasting a particular document in PasteClipboard", "Exception : " + docLevelException + " \n\n " + docLevelException.StackTrace);
                            }
                        }

                        clipboardWorkBox.Web.AllowUnsafeUpdates = false;
                    }
                }

                if (clipboardAction == CLIPBOARD_ACTION__CUT)
                {
                    // You cannot paste more than once items that have been cut:
                    ClearClipboard(userProfile);
                }

                workBox.Web.AllowUnsafeUpdates = allowUnsafeUpdatesOriginalValue;
            }
            catch (Exception exception)
            {
                WBUtils.SendErrorReport(workBox.Web, "Error in PasteClipboard", "Exception : " + exception + " \n\n " + exception.StackTrace);
                WBLogging.Generic.Unexpected("Clearing the user's clipboard in the hope that that will fix the error they are having.");
                ClearClipboard(userProfile);
            }


            return(clipboardAction);
        }