How to access SharePoint list data in custom Behavior

650
2
09-30-2013 05:57 AM
SatyamAMIN
New Contributor
Hello,

I am developming custom Behavior for "ArcGIS for SharePoint". I have started by selecting "ArcGIS viewer for Silverlight project".
In this project, there are two files  .xaml and MyBhavaior.cs file. I am using Silverlight client object model to get SharePoint list data in MyBhavaior.cs file, but my ClientContext  is always null and throws an error even though I get right URL of SharePoint site. Anyone can help me to resolve it ?

Please find implemented code below.

#region Behavior Overrides
protected override void OnAttached()
{
    base.OnAttached();
    List<string> KMZUrls = new List<string>();
    ClientContext _clientContext = new ClientContext(ApplicationContext.Current.Url);
    Web rootWeb = _clientContext.Site.RootWeb;   
    _clientContext.Load(rootWeb);
    List list = rootWeb.Lists.GetByTitle("SharePoint List");
    CamlQuery query = new CamlQuery();
    query.ViewXml = "<View><Query></Query></View>"; //List<string> KMZUrls = new List<string>();
    ListItemCollection items = list.GetItems(query);
    .......
}

Thanks,
Satyam
0 Kudos
2 Replies
AnhNguyen1
New Contributor
Have you tried this one: ClientContext clientContext = ClientContext.Current;
Instead of ClientContext clientContext = new ClientContext(ApplicationContext.Current.Url);
0 Kudos
SatyamAMIN
New Contributor
You made my day and saved a lot of time. It works. I don't understand yet that what you proposed me I had tried once but it was not worked.

Once again thank you very much.

Satyam
0 Kudos