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

Using a Provider Hosted Application for SharePoint 2013, I am unable to ue the following lines in my C# code to get the current user

SPWeb web = SPControl.GetContextWeb(this.Context);
SPUser sUser = web.CurrentUser;

The error is that it says I am unable to find namespace.

I tried to add the following to the top of the page, but WebControls does not exist.

using Microsoft.SharePoint.WebControls;

Any ideas of what I'm misisng?

thanks! Graham.

share|improve this question
Start with using Microsoft.SharePoint – Robert Lindgren May 16 '13 at 13:26
I am, I have that one declared as well, right above this one. – Graham May 16 '13 at 13:35
up vote 1 down vote accepted

So I was able to figure this out.

I was calling the wrong classes. Web and User where the ones i needed, not SPUser and SPWeb.

I also needed to execute the query to fill up web and current user. Here is a snippit of my code to create a dictionary of some variables.

using (var clientContext = TokenHelper.GetClientContextWithContextToken(hostWeb, contextToken, Request.Url.Authority)) {
            Web web = clientContext.Web;
            User currentUser = clientContext.Web.CurrentUser;

            clientContext.Load(web);  //, web => web.Title);

            //get timestamp
            string ts = DateTime.Now.ToString("yyyyMMddHHmmssfff");

            Dictionary<string, string> dictionary = new Dictionary<string, string>();
            dictionary.Add("name", currentUser.Title);
            dictionary.Add("email", currentUser.Email);
            dictionary.Add("timestamp", ts);

With this code, I am also able to grab content from the 'web' variable.

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.