visual-studio-2010sharepointsharepoint-2010windows-sharepoint-services

Get email administrators using wss 3.0


How could obtain all e-mail from site collection's administrators using wss 3.0?


Solution

  • Try:

       private string[] GetEmails(SPWeb web)
       {
           List<string> emails = new List<string>();
           Guid siteID = web.Site.ID;
           Guid webID = web.ID;
           using (SPSite site = new SPSite(siteID, SPUserToken.SystemAccount))
           {
               using (SPWeb web1 = site.OpenWeb(webID))
               {
                   SPUserCollection admins = web1.SiteAdministrators;
                   foreach (SPUser admin in admins)
                   {
                       emails.Add(admin.Email);
                   }
               }
           }
           return emails.ToArray();
       }
    

    Note that SiteAdministrators requires that the context user is a site collection auditor.