November 2008
M T W T F S S
« Oct   Dec »
 12
3456789
10111213141516
17181920212223
24252627282930

11
Nov
08

Make all Publishing Images document libraries anonymous reading ready.

 I wrote this when I needed to make all of my images folders purely anonymous reading. I dont want to ever run into an issue of an image that is not checked in. Create a console app and replace the main with the code below. It will crawl the whole site and make all images (publishing images) fully anonymous for reading.

 
 static void Main(string[] args) 
        { 
            bool requireApproval = false;
            // open the site 
            SPSite site = new SPSite(http://YOUR_SITE); 
            // open the web 
            SPWeb web = site.OpenWeb();
            ProcessWeb(web, requireApproval);
            return;
            // open the web collection 
            SPWebCollection webcoll = web.Webs;
            // parse through the webs 
            foreach (SPWeb webx in webcoll) 
            { 
                ProcessWeb(webx, requireApproval); 
            }
            Console.Read(); 
        }
        public static void ProcessWeb(SPWeb webx, bool requireApproval) 
        { 
            Console.Write("Processing " + webx.Url + "\n");
            // get the list 
            SPListCollection lists = webx.Lists;
            // looks for our Pages list 
            foreach (SPList siteList in lists) 
            { 
                if (siteList.Title == "Images") 
                {
                    //PublishingWeb pweb = PublishingWeb.GetPublishingWeb(webx);
                    //PublishingPageCollection ppages = pweb.GetPublishingPages();
                    bool fixSite = false;
                    siteList.EnableModeration = false; 
                    siteList.ForceCheckout = false; 
                    siteList.AllowEveryoneViewItems = false; 
                    siteList.DraftVersionVisibility = DraftVisibilityType.Reader; 
                    siteList.Update();
                    fixSite = true;
                    if (siteList.WorkflowAssociations.Count > 1) 
                    { 
                        SPWorkflowAssociationCollection wfCol = siteList.WorkflowAssociations; 
                        SPWorkflowAssociation wf = wfCol.GetAssociationByName("Parallel Approval", System.Globalization.CultureInfo.CurrentCulture);
                        wf.Enabled = false;
                        siteList.UpdateWorkflowAssociation(wf); 
                    } 
                } 
            }
            if (webx.Webs.Count > 0) 
            { 
                foreach (SPWeb webNext in webx.Webs) 
                { 
                    ProcessWeb(webNext, requireApproval);
                } 
            } 
        }

0 Responses to “Make all Publishing Images document libraries anonymous reading ready.”


  1. No Comments