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

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

javascript - Restarting Supervisor and effect on FlaskSocketIO -

php - Mongodb connectivity error -