public void DeleteFeatureFolders(SPWeb currentWeb, string[] foldersToDelete)
        {
            SPFolder folderToDelete = null;

            if (currentWeb != null)
            {
                foreach (var folder in foldersToDelete)
                {
                    folderToDelete = null;
                    try
                    {
                        folderToDelete = currentWeb.GetFolder(folder);
                    }
                    catch
                    {
                        folderToDelete = null;
                    }

                    if (folderToDelete != null)
                    {
                        try { folderToDelete.Recycle(); }
                        catch (Exception bEx)
                        {
                            // log error on delete
                        }
                    }
                }
            }
        }
Esempio n. 2
0
 public string Recycle()
 {
     return(m_folder.Recycle().ToString());
 }
        /// <summary>
        /// Does the paste action
        /// </summary>
        private void PasteHere()
        {
            // Pro
            // SiteUrl
            // FileUrl
            Debug.WriteLine("** _eventArgs: " + _eventArgs);
            string[] pasteData = _eventArgs.Split('|');
            SPSite   site;
            SPWeb    web;

            SPWeb  currWeb = SPContext.Current.Web;
            SPList list    = SPContext.Current.List;

            // Rootfolder contains the current folder
            string destinationFolderUrl = Page.Request.QueryString["RootFolder"];

            // Check for valid url
            // Default views (aka root folders) don´t contain a RootFolder QueryString
            if (string.IsNullOrEmpty(destinationFolderUrl))
            {
                destinationFolderUrl = currWeb.Url + "/" + SPEncode.UrlEncodeAsUrl(
                    NormalizeUrl(list.RootFolder.ToString()));
                // list.Title
            }

            try
            {
                // Open source site and to get the file or folder
                using (site = new SPSite(pasteData[1]))
                {
                    web = site.OpenWeb();

                    // Folder object from url
                    // Reopen too get elevated privileges
                    SPFolder destinationFolder = currWeb.GetFolder(destinationFolderUrl);

                    Debug.WriteLine("Destination Folder:" + destinationFolderUrl);
                    Debug.WriteLine("Source Site:" + pasteData[1]);
                    Debug.WriteLine("Source File-Folder:" + pasteData[2]);

                    // Paste the file
                    object fileOrFolder = web.GetFileOrFolderObject(pasteData[2]);

                    if (fileOrFolder is SPFile)
                    {
                        Debug.WriteLine("** Coping File");
                        SPFile file = fileOrFolder as SPFile;
                        CopyFile(file, destinationFolder);
                    }
                    else if (fileOrFolder is SPFolder)
                    {
                        Debug.WriteLine("** Coping Folder");
                        SPFolder folder = fileOrFolder as SPFolder;
                        CopyFolder(folder, destinationFolder);
                    }

                    //Delete the file if the action is "Cut"
                    if (pasteData[0].ToLower() == "ProCut".ToLower())
                    {
                        if (fileOrFolder is SPFile)
                        {
                            Debug.WriteLine("** Deleting File");
                            SPFile file = fileOrFolder as SPFile;
                            //file.Delete();
                            file.Recycle();
                        }
                        else if (fileOrFolder is SPFolder)
                        {
                            Debug.WriteLine("** Deleting Folder");
                            SPFolder folder = fileOrFolder as SPFolder;
                            folder.ParentWeb.AllowUnsafeUpdates = true;
                            //folder.Delete();
                            folder.Recycle();
                            folder.ParentWeb.AllowUnsafeUpdates = false;
                        }
                    }
                }

                RefreshPage();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }