| Brijesh's profileBrijesh's spacePhotosBlogLists | Help |
|
|
April 17 Custom code to get the list of site collection administrators for all the site collections in SharePoint server farmAlright
we have changed our idea of giving "Administrator" level access to all
the site collections to the outsourced team. Instead we decided to
deliver them an Excel document with the URL and site collection
administrators for each site collection. In fact, all the outsourced
team members have access to their own team site. So we are going to
upload this Excel document to their team site. As usual, I wrote C# console application to achieve this. Note: 1. This code assumes that you have all the site collections created under "sites/" 2. This is a console application so you have to use it the way you use stsadm command. 3. This code will output a text file with comma separated values when you run it as follows, SCAdmin.exe -url http://sharepoint.domain.com > SCAdmins.txt 4. Finally you can import SCAdmin.txt file to an Excel document with ","(comma) selected as separator for creating a new column. 5. SCAdmin.txt file should look like this, http://sharepoint.domain.com/sites/SC1, domain\spadmin; http://sharepoint.domain.com/sites/SC1, domain\spadmin; domain\user2; domain\user3 http://sharepoint.domain.com/sites/SC1, domain\user4; domain\user5; http://sharepoint.domain.com/sites/SC1, domain\spadmin; domain\user6 http://sharepoint.domain.com/sites/SC1, domain\user7; ............................... ................... ........ 6. When you import SCAdmin.txt to an Excel document by selecting "," (comma) as the separator, it will place URL in first column and site collection administrators in second column. Disclaimer: Please test this code in test environment before you use it. I will not be responsible the outcome of this code. Here is the code, using System; using System.Collections; using System.Collections.Generic; using System.Text; using Microsoft.SharePoint; using Microsoft.SharePoint.Administration; using Microsoft.SharePoint.StsAdmin; namespace SCAdmins { class SCAdminsClass { static void Main(string[] args) { SCAdminsClass sc = new SCAdminsClass(); sc.getSiteCollectionAdministrators(args); } private void getSiteCollectionAdministrators(string[] args) { try { string mode = ""; string virtualserver = ""; // get command line arguments if ((args.Length == 0) || (args.Length == 1 && (args[0] == "-?" || args[0] == "-help"))) { displayOutput("", mode); displayOutput("SCAdmin.exe -url VirtualServerURL [-quiet]", mode); displayOutput("", mode); displayOutput(" -url VirtualServerURL: Full URL of virtual server starting with http://", mode); return; } // loop through command line arguments for (int i = 0; i < args.Length; i++) { if (args[i] == "-url") { virtualserver = args[i + 1]; i++; // make sure url parameter starts with http: if (!virtualserver.StartsWith("http:")) { throw new ArgumentOutOfRangeException("url parameter should start with http://"); } } else if (args[i] == "-quiet") { mode = "quiet"; continue; } else { displayOutput(String.Format("Unrecognized switch {0}", args[i]), mode); return; } } // connect to web application on virtualserver SPWebApplication webApp = SPWebApplication.Lookup(new Uri(virtualserver)); // create site collections object for web application SPSiteCollection siteCollections = webApp.Sites; string SCUrl = ""; int SCCount = 0; SPSite site = null; SPWeb web = null; string admins = ""; // loop through site collections foreach (SPSite siteCollection in siteCollections) { site = new SPSite(siteCollection.Url); web = site.OpenWeb(); SCUrl = siteCollection.Url; if (SCUrl.Contains("sites")) { SCCount++; SPUserCollection users = web.Users; foreach (SPUser user in users) { if (user.IsSiteAdmin) { admins = admins+user.LoginName+"; "; } } Console.WriteLine(SCUrl + ", " + admins); } admins = ""; } //Console.WriteLine("Total Site Collection: " + SCCount); } catch (Exception e) { Console.WriteLine(e.Message); } } private void displayOutput(string text, string mode) { if (mode != "quiet") { Console.WriteLine(text); } } } } Please send me an email if you need a zip file for this C# project. Enjoy! April 16 How to add another site collection administrator to all the site collections in SharePoint server farm?First of all, let me make this clear that I am not a good SharePoint Developer but I have tried my best to achieve this programmatically. namespace AddSCAdmin private void addSiteCollectionAdmin(string[] args) // get command line arguments // loop through command line arguments // connect to web application on virtualserver string SCUrl = ""; private void displayOutput(string text, string mode) April 15 April 2008How to calculate age of list items in SharePoint: Here are the steps to calculate age of the list items in SharePoint, 1. Go to the list where you want to calculate age of the items e.g. Task List 2. Click Settings => List Settings and create a new column and name it e.g. "Today", There is no need to select any specific type for this column (Just type the name of the column and click "OK" at the bottom) 3. Create one more column and name it e.g. "Age in Days". Select "Calculated(calculation based on other columns)" type and provide formula using "Today" column which you created in step 2 e.g. I have entered =[Today]-[Created]. Select "number" for the data type and 0(zero) in "Number of Decimal places". So basically it will calculate difference between today's date and date the item was created. 4. After 3rd step, remove "Today" column, which you have created in step 2. When you remove Today column, SharePoint automatically refers "Today" (which has been deleted now) as the today's date in the formula calculation. 5. Go back to Task List and it should display the number of days under the "Age in Days" column of each items in Task List. |
|
|