[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2016-10-02
3
Medium Priority
?
103 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 44

Accepted Solution

by:
zephyr_hex (Megan) earned 2000 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 44

Expert Comment

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

656 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