Sunday, 22 July 2012

Delete dynamic pages


            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = SPContext.Current.Site)
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        using (VCSBINTRANETDataContext datacontxt = new VCSBINTRANETDataContext(SiteHelper.SiteUrl))
                        {
                            var itemDelete = (from deletequery in datacontxt.PropellerStudio
                                              where deletequery.Id == Convert.ToInt32(propellerStudioBL.ID)
                                              select deletequery).First();
                            PublishingWeb pubWeb = null;
                            if (PublishingWeb.IsPublishingWeb(web))
                            {
                                pubWeb = PublishingWeb.GetPublishingWeb(web);

                                foreach (SPListItem currentItem in pubWeb.PagesList.Items)
                                {
                                    if (PublishingPage.IsPublishingPage(currentItem))
                                    {
                                        PublishingPage page = PublishingPage.GetPublishingPage(currentItem);

                                        if (itemDelete.Title + ".aspx" == page.Name)
                                        {
                                            if (page.Name != pubWeb.DefaultPage.Name)
                                            {
                                                currentItem.File.Delete();
                                                datacontxt.PropellerStudio.DeleteOnSubmit(itemDelete);
                                                datacontxt.SubmitChanges();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            });

2 comments:

  1. Hey, you have an interesting blog. You blog has been included in my blog that is exclusively dedicated to Coimbatore bloggers. Hope to see more posts from you. I am a writer and I love reading blog posts.

    ReplyDelete

SharePoint online - Get List-item attachments and Display to div

Step 1 : Create a List ex: TestList and attach few images Step 2 : Copy and Pastet the below coding in App.js var  Items =  null ; ...