locked
get contenttype on root site RRS feed

  • Question

  • Hey,


    I'm trying to get the data in a contenttype on the top level site on my web site when I'm on a subsite

    I'm using the following code:
    Code Block

    Dim Web as SPWeb
    Web = SPContext.Current.Site.RootWeb

    xmlString = SPContext.GetContext(Web).ListItem.GetFormattedValue("CfgDepartment")



    This works great when I'm actualle on the level site (Http://test.localhost) but when I try to get the data from a subsite (http://test.localhost/department) I get a error. Object reference not set to an instance of an object.

    I have tried printing the web.url out and on both the toplevel site and the sub site it comes out "http://test.localhost"

    Anyone got any ideas on how to fix this.

    Regards
    Birger
    Tuesday, December 18, 2007 12:58 PM

Answers

  •  

    When you do "GetContext" and then ".ListItem" the code assumes you are on a page that is associated with a list item. This will not work from other pages.

     

    Instead, you should change the code to load the list item you want from the list you want. Take a look at my blog post Common and Simple coding tasks in sharepoint for examples on how to connect to lists and how to get list items.

    Tuesday, December 18, 2007 11:15 PM

All replies

  •  

    When you do "GetContext" and then ".ListItem" the code assumes you are on a page that is associated with a list item. This will not work from other pages.

     

    Instead, you should change the code to load the list item you want from the list you want. Take a look at my blog post Common and Simple coding tasks in sharepoint for examples on how to connect to lists and how to get list items.

    Tuesday, December 18, 2007 11:15 PM
  • Hey,
    Thanks for the reply.
    I've tried looking at your site but so far I can't get it to work.
    When I try to load the contenttype into a list I just get a error saying something about result is out of expected range(can't remenber the precise error)


    I was of the understanding that when I used the getcontext(web) I would get the list of the SPWeb represented by "web". This is in this case the root level site.


    regards
    Birger
    Wednesday, December 19, 2007 10:31 AM