Monday, 22 April 2013

How to get list item by absolute URL of the item

Pass the URL as query string named DocumentPath.


  protected void Page_Load(object sender, EventArgs e)
        {
            string documentPath = Convert.ToString(Request.QueryString["DocumentPath"]);
            if (string.IsNullOrEmpty(documentPath))
            {
            }
            else
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite site = new SPSite(SPContext.Current.Site.ID))
                    {
                        using (SPWeb web = site.RootWeb)
                        {

                            SPListItem item = web.GetListItem(documentPath);
                        }
                    }
                });


            }


        }

            }

        }