Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.
share|improve this question
add comment

2 Answers 2

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()
share|improve this answer
    
That's what I thought, however when I try with the first statement I get an: “Object reference not set to an instance of an object.” error and the second statement gives the error: “Cannot complete this action. Please try again.” Which is very weird as SPContext.Current.Site and SPContext.Current.Web both work. –  Rob Feb 22 '10 at 9:48
    
Hmm strange - I'm pretty sure I've written code like this in a HTTP handler before. Is it perhaps that SPContext is populated by the .List property isn't? –  Chris O'Brien - MVP Feb 22 '10 at 11:36
    
Hi Chris thanks for replying, i've posted my code as it might be easier to see if i'm making a mistake somewhere else. –  Rob Feb 22 '10 at 12:27
add comment
up vote 0 down vote accepted

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.