1

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.
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()
  • 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
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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