Solved

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

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

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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