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:
- what
sitecore.context.database
when execute code?web
,master
, or maybecore
? - what id passed method? valid id wanted pass?
- does item id exist in database (e.g. published
web
database)?
Comments
Post a Comment