How to get item in WebMethod using Sitecore? -


i have created 1 webmethod, in method want access item path.

[webmethod] [system.web.script.services.scriptmethod(usehttpget = true)] public static int itemcount() {      int val = 0;      item itm = sitecore.context.database.getitem("id there");      val = itm.children.count;      return val; } 

but getting error "object reference not set instance of object". can suggest me how can use it?

thanks in advance

object reference exception can happen in code when getitem method returned null.

3 things need check are:

  1. what sitecore.context.database when execute code? web, master, or maybe core?
  2. what id passed method? valid id wanted pass?
  3. does item id exist in database (e.g. published web database)?

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -