Get current list/library from http handler

Rob
  • Get current list/library from http handler Rob

    I’m trying to write a Http Handler to generate rss xml (based on the CKS code).

    I want to be able to get the list/library that the end point of the url is referring to.

    For example if my Url is:

    I want to be able to get the pages library of the 'press releases' web.

    On a side note if I'm going about this in the wrong way please let me know.

    Update 1

    It may be easier for me to show my code (incase of retardation)

    public void ProcessRequest(HttpContext context)
        {
    
            try
            {
                SPList list = SPContext.Current.Web.GetListFromUrl(context.Request.Path);
            }
            catch (Exception ex)
            {
                context.Response.Write("Error getting list from spcontext.current.web.GetListFromUrl: " + ex.Message + "<br />");
            }
    
            try
            {
                SPList list = SPContext.Current.List;
                context.Response.Write("List title: " + list.Title.ToString() + "<br />");
            }
            catch (Exception ex)
            {
                context.Response.Write("Error getting list from spcontext.current.list: " + ex.Message + "<br />");
            }
    
            try
            {
                context.Response.Write("List Title from SPConext: " + SPContext.Current.List.Title.ToString());
            }
            catch (Exception ex)
            {
                context.Response.Write("Error getting list from spcontext.current.list.title.tostring: " + ex.Message + "<br />");                
            }
    
        }
    

    The error messages displayed are...

    • Error getting list from spcontext.current.web.GetListFromUrl: Cannot complete this action. Please try again.
    • Error getting list from spcontext.current.list: Object reference not set to an instance of an object.
    • Error getting list from spcontext.current.list.title.tostring: Object reference not set to an instance of an object.

  • You have access to SPContext within a HTTP handler, so you should be able to use:

    SPContext.Current.List
    

    If for some reason that can't be used, this should get you there:

    SPContext.Current.Web.GetListFromUrl()
    

  • I've managed to get the list name by string manipulation.

Tags
2007 publishing-site rss
Related questions and answers
  • ); System.Console.WriteLine(meta.Title); } } } As you can see, I fetch all the lists using GetListCollection and then, if it is a survey, I try to get the List information using GetList. I use the List GUID as the list name. An exception is thrown. The SOAP body is shown below. &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; &lt;soap:Body> &lt;soap:Fault> &lt;faultcode>

  • correctly for the Content Editor Web Part (based on sample code), however when I replace the Content Editor Web Part definition with one for my own web part I get the following error...()); } UPDATE: Based on feedback from Wictor, I tried the following: &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;webParts> &lt;webPart xmlns="http://schemas.microsoft.com/WebPart/v3"&gt; &lt...;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;"; //webPartXml = webPartXml + "&lt;WebPart xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns

  • as expected. When I try to add a new item to the list, the list form only shows the Title field from Item. Now, here's the weird part. If I add a second content type to the list (through the UI), the list form suddenly works correctly. This makes me think there's something wrong with my content type. Here's what I'm working with. Some names have been changed to protect the innocent. &lt;ContentType... xmlns:ows="Microsoft SharePoint" Title="Withdrawals" FolderCreation="FALSE" Direction="LTR" Url="Lists/Withdrawals" EnableContentTypes="TRUE" BaseType="0"&gt; &lt;MetaData> &lt;ContentTypes>

  • I’ve been trying to use ListData.svc to get a REST feed from a list (actually a pages library) using something like: http://SharePoint/_vti_bin/ListData.svc/Pages?$orderby=NewsArticleDate&$filter=(2010 eq year(NewsArticleDate)) and (06 eq month(NewsArticleDate)) and (ContentType eq 'News Article') It all works great and our front-end developers have been able to combine this feed... on anonymous access (anonymous users can browse to the list items) this feed simply returns an error: Object reference not set to an instance of an object. Is it just not possible to use this service

  • , and then as part of that activation, drop web parts onto some specific pages. In my case I want to be able to drop it onto the "AllItems.aspx" page of a list, but I'm equally having trouble adding...), then there doesn't seem to be a way to just get a reference to the page, it always wants to overwrite it with a new file. But I dont want to do that, I just want to add a Web Part to the existing page. See my... someone else has cracked this nut. &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;Elements xmlns="http://schemas.microsoft.com/sharepoint/"&gt; &lt;Module Name="Pages"&gt; &lt;File Path="" Url

  • , this is the reason for my post. I cannot get this code to execute from within a console application. Does the SPList.SaveAsTemplate method require a HttpContext? If it does it is not metioned in any of the docs...() End If End If Try List.Delete() Catch ex As Exception Return False End Try Return True End Function This is very much a work...I have never really had too much cause to use this method before but I am developing some generic classes to deal with column, content type and list management for use in a series of features. My

  • I've created a Custom List ('Tooltips') in SharePoint. After this I used SPSource to reverse engineer the list into a feature. After installing and activating this feature, I want to add this list in a WebPart zone. When doing this, I get an error message : Tooltips: List View Web Part could not be added, list may be hidden. What's wrong with the list? feature.xml &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;Feature Id="70d49f3d-233a-482d-97e3-dcec2c236171" Title="MyApp - Tooltips" Description="Creates a Tooltips list which can be used for mouse-over texts

  • ;Elements Id="9e85eb79-6d8d-4ff3-b0d4-64d55c3bb577" xmlns="http://schemas.microsoft.com/sharepoint/"&gt; &lt;Module Name="Pages" Url="Pages"&gt; &lt;File Path="Example.aspx" Url...="~masterurl/default.master"%&gt; &lt;%-- deliberately left empty --&gt; (yup, it's empty!) Addendum When I "visit the pages in-browser" I mean navigate to their URLs manually: http://myserver:PORT/subsite/Pages/Example.aspx When I "View All Site Content" I am looking at the contents of the "Pages" list: http://myserver:PORT/subsite/Pages/Forms/AllItems.aspx

  • [A content has been removed from Latest Events. &lt;br/&gt;Thank You]]&gt; &lt;/HTML> &lt;/Case> &lt;Default> &lt;GetVar...I've customized alert notification template for Announcements list. Here is custom code: &lt;Immediate> &lt;Subject> &lt;Switch> &lt;Expr> &lt;GetVar Name...; &lt;Case Value = "1"&gt; &lt;HTML> &lt;![CDATA[A new content has been added to Latest Events. To view, please visit: &lt;a href

Data information