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

  • Home
  • SEARCH
  • 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 8964799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:40:17+00:00 2026-06-15T16:40:17+00:00

I have a custom SharePoint web part that I have deployed as farm solution

  • 0

I have a custom SharePoint web part that I have deployed as farm solution and am having issues writing to a SharePoint list. Despite setting AllowUnsafeUpdates to True (in many different places) and updating the SPWeb object prior to calling the SPListItem update, the following is the error message I experience when programatically writing to a list:

Updates are currently disallowed on GET requests. To allow updates on a GET, set the ‘AllowUnsafeUpdates’ property on SPWeb.

I have also tried using RunWithElevatedPrivileges, but no luck.

Here is my code for your reference:

        public void WriteError(string errorTask, string errorMessage)
        {
            string task = "Error Log Entry";
            string fileName = "";
            string fileTitle = "";
            string fileType = "";

                using (SPSite oSiteCollection = new SPSite(SPContext.Current.Web.Url))
                {
                    using (SPWeb oWebsite = oSiteCollection.RootWeb)
                    {
                        oSiteCollection.AllowUnsafeUpdates = true;
                        oWebsite.AllowUnsafeUpdates = true;
                        oWebsite.Update();

                        SPSite errorLogSite = new SPSite(oWebsite.ServerRelativeUrl);
                        SPListItemCollection oList = errorLogSite.RootWeb.Lists["ErrorLog"].Items;

                        SPListItem oItem = oList.Add();
                        oItem["ErrorTask"] = task + ": " + errorTask;
                        oItem["ErrorMessage"] = errorMessage;
                        oItem["UserName"] = String.IsNullOrEmpty(UserName) ? "Not Available" : UserName;
                        oItem["FileName"] = String.IsNullOrEmpty(fileName) ? "Not Available" : fileName;
                        oItem["Title"] = String.IsNullOrEmpty(fileTitle) ? "Not Available" : fileTitle;
                        oItem["FileType"] = String.IsNullOrEmpty(fileType) ? "Not Available" : fileType;

                        oItem.Update();
                    }
                }

        }
  • 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-15T16:40:19+00:00Added an answer on June 15, 2026 at 4:40 pm

    It seems that you do not fully understand the goal of AllowUnsafeUpdates property of SPWeb.
    You should set it to true on that SPWeb instance, which you are using for SPList instance retrieving. Also there is no reason to create so much instances of SPSite and SPWeb as it may degrade performance. For your case try next code

    public void WriteError(string errorTask, string errorMessage)
            {
                string task = "Error Log Entry";
                string fileName = "";
                string fileTitle = "";
                string fileType = "";
    
                var errorLogWeb = SPContext.Current.Site.RootWeb;
                errorLogWeb.AllowUnsafeUpdates = true;
                var errorLogList = errorLogWeb.Lists["ErrorLog"];
                SPListItem oItem = errorLogList.Items.Add();
                oItem["ErrorTask"] = task + ": " + errorTask;
                oItem["ErrorMessage"] = errorMessage;
                oItem["UserName"] = String.IsNullOrEmpty(UserName) ? "Not Available" : UserName;
                oItem["FileName"] = String.IsNullOrEmpty(fileName) ? "Not Available" : fileName;
                oItem["Title"] = String.IsNullOrEmpty(fileTitle) ? "Not Available" : fileTitle;
                oItem["FileType"] = String.IsNullOrEmpty(fileType) ? "Not Available" : fileType;
    
                oItem.Update();
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom Sharepoint 2010 web part that runs the user through a
I have created a SharePoint web part which has custom properties that the user
I have a problem with SharePoint custom web part. It was successfully deployed and
I have a custom web application that integrates with a SharePoint (MOSS 2007) solution.
I have a web part that for new and edit functionality for custom list.
I have a custom sharepoint web part that is throwing the following exception: System.Security.SecurityException:
I would like to have a custom web part page in SharePoint 2007. I
We currently have a product that uses Sharepoint and a number different Web Part
Background: I have a built-in-house custom SharePoint 2010 web part, inheriting from System.Web.UI.WebControls.WebParts.WebPart ,
Currently I have a custom Web Part, deployed as a Feature, and it accesses

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.