I'm trying to retrieve list from Sharepoint using C# and get that list using JavaScript from client.
Can someone help me?
This is my C# code.
SPWeb web = SPContext.Current.Web;
SPList maListe = web.Lists["Lycee"];
SPListItemCollection mesItem = maListe.Items;
foreach (SPListItem monItem in mesItem)
{
//get Liste but i don't kwnow what to do?
}
you can use javascript to access the list directly as following code sample
$(function () {
ExecuteOrDelayUntilScriptLoaded(retrieveListItems, "sp.js");
});
var siteUrl = '/sites/MySiteCollection';
function retrieveListItems() {
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('Lycee');
this.collListItem = oList.getItems();
clientContext.load(collListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded(sender, args) {
var listItemInfo = '';
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
listItemInfo += '\nID: ' + oListItem.get_id() +
'\nTitle: ' + oListItem.get_item('Title')
}
alert(listItemInfo.toString());
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
to read more documentation check following link
it's working now.
i just call my function like this.
_spBodyOnLoadFunctionNames.push("getListLycee");
tanks for your help.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.