TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Murali Kris
1.5k
254
48.7k
Error while adding a user to site collection administrator
Sep 16 2017 5:04 AM
Hi All,
please help me from below issue.
get-access is button it reads input from text box , and it has to add that user id in to as a site collcetion administrator.
please see below code. where i am getting error.
private void button10_Click(object sender, EventArgs e)
{
string adduser = string.Empty;// textBox4.Text.Trim();
adduser = textBox4.Text.Trim();
if (Context == null)
{
Context = Get_Context();
}
Context.Load(Context.Site);
Context.Load(Context.Site.RootWeb);
Context.Load(Context.Site.RootWeb.SiteUsers);
Context.ExecuteQuery();
foreach (var scUser in Context.Site.RootWeb.SiteUsers)
{
if (scUser.IsSiteAdmin)
{
//here i am getting error
User user =
Web.EnsureUser
(adduser);
// another formate tryed below also getting error same .
User user =
Web.EnsureUser
(@"domain\username").ToString();
Error :
an Object referance is required for the non-static field, method, or property 'web.ensureUser(string)'
// Context.Site.RootWeb.SiteUsers.AddUser()
// Context.Site.RootWeb.SiteUsers.AddUser(scUser.Id);
//Context.Site.RootWeb.SiteUsers.AddUser(user);
Context.Site.RootWeb.SiteUsers.AddUser(user);
}
}
please can any one help me here.
Reply
Answers (
1
)
I am Building A Universal Windows Platform Game?
Amazon SNS (Simple Notifiaction Services) using .net