Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8453217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:42:43+00:00 2026-06-10T11:42:43+00:00

I have added usercontrol on a sharepoint 2007 site. When I add an item

  • 0

I have added usercontrol on a sharepoint 2007 site. When I add an item it gets added as I’m the site admin. But when my friends try to login it throws “Unable to evaluate expression bcoz the code is optimized or native frame is on top of the stack” On list.update() and on the site it displays Access denied error.

The following is the code:

protected void btnOk_Click(object sender, EventArgs e)
{   
    try
    {             
        using (SPSite site = new SPSite("http URL"))
        {
            using (SPWeb web = site.OpenWeb())
            {
                SPList list = web.Lists["List name"];
                UserItem = list.Items.Add();
                UserItem["col 1"] = Data1;
                UserItem["col 2"] = Data2;
                UserItem["col 3"] = Data3;
                UserItem["col 4"] = Data4;
                UserItem["col 5"] = Data5;
                UserItem.Update();
                list.Update();
            }
        }
    }
}

I have also tried the below URLs:

  • http://frazzleddad.blogspot.in/2011/03/getting-past-sharepoint-exceptions-with.html
  • http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.catchaccessdeniedexception.aspx

But even that is not working.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:42:45+00:00Added an answer on June 10, 2026 at 11:42 am

    This could occur when your friends dont have the required previlages .Every thing works fine for u being a Site admin. One thing you need to do is modify your btnOk_Click code as shown below.

     SPSecurity.RunWithElevatedPrivileges(delegate()
     {
       using (SPSite site = new SPSite("http URL"))
        {
            using (SPWeb web = site.OpenWeb())
            {  
                web .AllowUnsafeUpdates = true;
                SPListItemCollection listitems = web.Lists["List name"].Items;
                SPListItem userItem = listitems.Add();
                userItem ["col 1"] = Data1;
                userItem ["col 2"] = Data2;
                userItem ["col 3"] = Data3;
                userItem ["col 4"] = Data4;
                userItem ["col 5"] = Data5;
                userItem.Update();               
                web .AllowUnsafeUpdates = false;
            }
        }
      });
    

    try this…hope it will work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UserControl which I have added to my web.config <add tagPrefix=BCF src=~/controls/MyMessageBox.ascx
WPF controls have certain properties (UserControl.Resources, UserControl.CommandBindings) that can have items added to them
I have added a plugin called scrollpaper to a site I'm working on. The
I have a usercontrol used in a masterpage. I have added a page with
In my MainWindow.xaml, I have added my UserControl to the Window. There is also
I have a FlowLayoutPanel and want to add series of UserControl to it: mainPanel.Controls.Add(fx);
I have created a UserControl, and added a couple of custom routed events. The
I have a UserControl that I need to add dynamically. I tried to follow
I have a ContainerPanel to which I added a UserControl. Is there a way
I have a UserControl that is added to my Main window. The Main code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.