Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.
SPUtility.ValidateFormDigest();
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPSite siteColl = SPContext.Current.Site;
                    SPWeb webSite = siteColl.OpenWeb();

                    int getIDProjectList = Convert.ToInt32(Request.QueryString["ID"]);

                    SPListItem attachmentToDelete = webSite.Lists["Projects List"].GetItemById(getIDProjectList);

                    SPFolder folders = attachmentToDelete.ParentList.RootFolder.SubFolders["AttachmentFiles"];
                    folders.SubFolders[getIDProjectList.ToString()].Delete();
                    folders.Update();

                });
share|improve this question

2 Answers 2

up vote 0 down vote accepted
            ValidateFormDigest();
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                SPSite siteColl = SPContext.Current.Site;
                SPWeb webSite = siteColl.OpenWeb();
                int getIDProjectList = Convert.ToInt32(Request.QueryString["ID"]);

                SPListItem attachmentToDelete = webSite.Lists["Projects List"].GetItemById(getIDProjectList);

                webSite.Folders[attachmentToDelete].SubFolders.Delete(getIDProjectList.ToString());
            });

Use the SPWeb object to delet the folder, using above code!

share|improve this answer
    
I tried the code below and get an Access Denied under Contributor Permissions. This works under Owner Permissions. webSite.Folders["Lists"].SubFolders["Projects"].SubFolders["AttachmentFiles"].Su‌​bFolders.Delete(getIDProjectList.ToString()); –  Michele DuBose Apr 4 '13 at 15:34
    
if you want the person to delete the folder than you can encapsulate it with an impersonation which will do the trick for you! checkout my answer here: sharepoint.stackexchange.com/questions/54607/… –  ali Sharepoint Apr 5 '13 at 8:16
    
Thanks @ali Sharepoint. This worked! The only thing I had to add was a 'website.AllowUnsafeUndates=true' because when i ran your suggested code, I got a 'security validation for this page is invalid....' message. –  Michele DuBose Apr 9 '13 at 15:48
    
thats no problem happy to help! just remember once you have done the update to set website.AllowUnsafeUndates = false; ;) , also please mark this as an answer for other people with the same issue! –  ali Sharepoint Apr 10 '13 at 7:57

I think your mistake is here
folders.SubFolders[getIDProjectList.ToString()].Delete();
It's strange behavior for me to delete a folder using ID of listitem such as number of element in collection.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.