Solved

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

Posted on 2016-10-02
3
64 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 (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 42

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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. …
There is one common problem that all we SharePoint developers share: custom solution deployment. This topic can't be covered fully in this short article, so all I want to do in this one is to review it from a development-to-operations perspectiv…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

932 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

11 Experts available now in Live!

Get 1:1 Help Now