SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I get the following exception message:

{"Attempted to perform an unauthorized operation."}
at Microsoft.SharePoint.SPSite.get_Owner()
at MySite.Intranet.QuickLinks.MySiteviewpage.GetSiteOwner()

When trying to run the following code:

    private string GetSiteOwner()
        string email = string.Empty;

        SPSite siteCollection = new SPSite(SPContext.GetContext(System.Web.HttpContext.Current).Site.Url);

        SPWeb site = siteCollection.OpenWeb();

            using (site)
                email = site.Owner.Email; //HITTING THE OWNER CAUSES THE EXCPTION

        return email;

Can anyone help please?

share|improve this question
I presume you're running this from a web part or something? – SHug Nov 25 '11 at 14:00
Yea, it is a custom control – Burt Nov 25 '11 at 14:22
Does the ULS log show anything in particular when this is running? – SHug Nov 25 '11 at 15:25
up vote 1 down vote accepted

If you are going to use SPSecurity.RunWithElevatedPrivileges() you need to put it around where you instantiate your SPSite and SPWeb objects.

Also, when "newing up" your SPSite and SPWeb objects, you need to ensure you dispose of them otherwise you'll have memory leak issue. (Have a look here for examples)

Try this:

private string GetSiteOwner() 
    string email = string.Empty; 

        using(SPSite siteCollection = new SPSite(SPContext.Current.Site.Url))
            email = siteCollection.Owner.Email; 
    return email; 

(I've removed the SPWeb reference as SPWeb doesn't contain an Owner property)

share|improve this answer

Your Answer


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.