Solved

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

Posted on 2016-10-02
3
77 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 43

Accepted Solution

by:
zephyr_hex (Megan) 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 43

Expert Comment

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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

830 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