SharePoint 2013 – GetListByName vs SPWeb.GetList vs SPListCollection.GetList vs SPListCollection.TryGetList

Getting a list with CSOM

In my PowerShell script I’m doing the following:

$list =  $web.Lists[“Mylist”]

This generates the following Unexpected error in my SharePoint logs:

8ca3ea94-3288-49cd-99fd-1b6eab6cb52d Stack trace: at Microsoft.SharePoint.SPListCollection.GetListByName(String strListName, Boolean bThrowException) at CallSite.Target(Closure , CallSite , Object , Object ) at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)

Am I doing something wrong. Not really as I’m getting my list object from SharePoint and all seems to be working.

I don’t like unexpected error as they tend to point towards something that isn’t handled properly.

How about using the GetList method?

I changed my code to:

$ulsList = $web.GetList($web.Url + “/lists/” + $ULSListName)

One Unexpected is now replaced with another one:

c50dac63-ae98-4054-9cb9-615373cfd553 Stack trace: at Microsoft.SharePoint.SPWeb.GetList(String strUrl) at CallSite.Target(Closure , CallSite , Object , Object ) at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0) at System.Management.Automation.DlrScriptCom…

hmm, So what could be the issue?

 

Get a list using TryGetList

Then I tried another option

$ulsList = $web.Lists.TryGetList($ULSListName)

No more errors.

How many options can there be to get a list???

 

 

 


Discover more from SharePains

Subscribe to get the latest posts sent to your email.

Related Posts

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from SharePains

Subscribe now to keep reading and get access to the full archive.

Continue reading