Solved

Sharepoint client object(ClientContext) model is not fetching/getting list value everytime

Posted on 2016-10-02
3
52 Views
Last Modified: 2016-10-12
A web Application uses SharePoint client object model to interact with sharepoint and get the list values. We found that approximately 50% time, it gets value from SharePoint 2010 SP 2. List has image path and image is stored in web application path.

We don't have privilege to login to web application production server to test the following code to test the connectivity.
I there any other we can figure of the root cause of the issue.

When I do testing locally it works and problem occur only in production. Can somebody help me to find root cause.

Microsoft.SharePoint.Client.ListItemCollection listItems = null;
    using (ClientContext clientContext = new ClientContext(String.Concat(SharePointUrl, serverRelativeUrl + sitePath)))
    {
        clientContext.Credentials = new NetworkCredential(sharePointUserName, sharePointPasswd, sharePointDomain);
        Web site = clientContext.Web;
        list = site.Lists.GetByTitle(listTitle);

        CamlQuery camlQuery = new CamlQuery();
        camlQuery.ViewXml = "<View/>";

        listItems = list.GetItems(camlQuery);

        clientContext.Load(list);
        clientContext.Load(listItems);
        clientContext.ExecuteQuery();
    }
    Count.Text = listItems != null ? listItems.Count.ToString() : "0";

Open in new window

0
Comment
Question by:Palanivelrajan
  • 2
3 Comments
 
LVL 42

Accepted Solution

by:
zephyr_hex earned 500 total points (awarded by participants)
ID: 41826949
I'm assuming that when it doesn't work, there's no error, right?

If that's the case, you could add some error handling with try / catch clauses (or ExceptionHandlingScope -- but that seems like a bit overkill for your case).

My first guess would be this is a failure to authenticate.  Or are the same credentials always passed?
If it's not always the same credentials, I'd recommend that you attempt to load the site:
Web site = clientContext.Web;
try 
{
     clientContext.Load(site);
     clientContext.ExecuteQuery();
     list = site.Lists.GetByTitle(listTitle);
     // etc
     clientContext.Load(list);
     clientContext.Load(listItems);
     clientContext.ExecuteQuery();
} catch (Exception e) 
{
      //do something with e
}

Open in new window


If the credentials are always the same, there's probably no point in testing if ExecuteQuery() will bomb on loading the site.  But it might be worthwhile to wrap your existing code with try / catch to throw exceptions.

Here is more on the topic of exception handling in Sharepoint CSOM:
http://ranaictiu-technicalblog.blogspot.com/2010/08/sharepoint-2010-exception-handling.html
0
 
LVL 42

Expert Comment

by:zephyr_hex
ID: 41834496
Did this answer your question?
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Note:  There are two main ways to deploy InfoPath forms:  Server-side and directly through the SharePoint site.  Deploying a server-side InfoPath form means the form is approved by the Administrator, thus allowing greater functionality in the form. …
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now