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 534215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:35:20+00:00 2026-05-13T09:35:20+00:00

Sometimes users require to change information in SharePoint list item that is not editable

  • 0

Sometimes users require to change information in SharePoint list item that is not editable for them, for instance, a field that is hidden in edit form (in my case it was the records number).

I decided to create a small Windows GUI application that the administrator would run on the server and make the requested change. However, the simplest scenario to get an instance of a SPListItem I found was:

  • the admin enters the URL of the root site
  • an SPSite ojbect is created, using the given URL: SPSite oSite=new SPSite(this.txtURL.text);
  • admin enters the relative URL of the reqired web
  • an SPWeb object is created as SPWeb oWeb = oSite.OpenWeb(this.txtWebUrl.text);
  • a dropdown box is filled with all the list titles from oWeb.Lists
  • admin chooses a list from the listbox and enters the ID of the requested item;
  • the needed SPListItem is found as oWeb.Lists[this.lstAllLists.selectedValue].GetItemById(this.txtItemId.value);

This is a very long path and administrators do no like to do the typing, clicking and waiting.
They would like to copy the URL of the listitem’s display form (from the web browser or somebody’s email), paste it into the update tool, then just click “Find it!”.

I need hints for how this can be done.

I know I could probably parse the URL with a regex, since it’s typically in the form of http://server/sites/[somesite]/[someweb/somesubweb]/lists/[somelist]/forms/dispform.aspx?ID=[123], but variations exist – for instance, http://[server]/[DocumentLibrary]/Forms/RenamedDispForm.aspx?ID=[1234] has quite different structure than the first example.

So, the question is – is there some easy way to find an SPListItem by it’s URL? Reconstructing an SPContext from the URL would be great.

EDIT: Just found out that it is possible to construct a valid SPSite object by passing it a much longer URL:

Dim oSite as New SPSite("http://server/sites/site/Lists/test/DispForm.aspx?ID=136")
  • 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-05-13T09:35:20+00:00Added an answer on May 13, 2026 at 9:35 am

    Found a solution myself, the trick I did not know is that if you use a long URL in the constructor of the SPSite, it gives you the SPWeb object with the “deepest possible” address that matches your url (described here: http://msdn.microsoft.com/en-us/library/ms473155.aspx)

    Still, I have to loop through all the lists to find out which list has the required URL. A simple function that does what I need:

    UPDATE @ 2012-08-01:

    • no need to loop through list collection, there is a GetList method
      in SPWeb object.
    • instead of doing regex on URLs, one can use
      HttpUtility.ParseQueryString method

    Hence the code now looks like this:

    Function GetItemByUrl(spUrl As String) As SPListItem
        'A site object does not care about additional parameters after site's URL
        Dim oSite As New SPSite(spUrl)
        'This returns the deepest SPWeb it can find
        Dim oWeb As SPWeb = oSite.OpenWeb()
        'here we parse out the ID parameter
        Dim oUri As New Uri(spUrl)
        'HttpUtility is from System.Web namespace
        Dim oQueryParams As System.Collections.Specialized.NameValueCollection 
        oQueryParams = HttpUtility.ParseQueryString(oUri.Query)
    
        Dim sParamval As String = oQueryParams.Get("ID")
        If (sParamval.Length <= 0) Then
            Return Nothing
        End If
    
        'This is how we get the list
        Dim oCurrentList As SPList = oWeb.GetList(spUrl)
        'And finally fetching the item
        Dim oListItem As SPListItem = oCurrentList.GetItemById(Int32.Parse(sParamval))
        Return oListItem
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.