programming4us
programming4us
WEBSITE

Sharepoint 2010 : Client Object Model - Adding Data, Updating Data

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

Adding Data

Adding data using the Client Object Model is a relatively straightforward process, as these snippets show. However, the ListItemCreationInformation object can also be used to set a few system properties when creating a new list item. For example, when you’re creating a list item within a folder, you can use the FolderUrl property to specify the location of the folder.

The following code sample shows how a new list item can be added using the Silverlight Client Object Model:

private void Add_Click(object sender, RoutedEventArgs e)
{
ClientContext ctx = new ClientContext("Your Server Here");
List announcements = ctx.Web.Lists.GetByTitle("Announcements");
ListItemCreationInformation createInfo = new ListItemCreationInformation();
ListItem newItem = announcements.AddItem(createInfo);
newItem["Title"] = "A new item";
newItem.Update();
ctx.ExecuteQueryAsync((s, args) =>
{
Dispatcher.BeginInvoke(() =>
{
label1.Content = "Item Added";
});

}, (s, args) =>
{
Dispatcher.BeginInvoke(() =>
{
label1.Content = args.Message;
});
});
}



When using the JavaScript object model, the code is similar:

function Add_Click() {
var ctx = new SP.ClientContext.get_current();
var announcements = ctx.get_web().get_lists().
getByTitle("Announcements");
var createInfo = new SP.ListItemCreationInformation();
var newItem = announcements.addItem(createInfo);
newItem.set_item("Title", "A new javascript item");
newItem.update();
ctx.executeQueryAsync(function (s, args) {
var console = document.getElementById('DemoConsole');
console.innerHTML = "Add Completed";
}, null);
}

Updating Data

So far, you’ve seen a few ways to retrieve data using the Client Object Model, as well as how to add new items to SharePoint lists and libraries. Our next logical step is to look at how we can update the data that we’ve retrieved and submit the changes back to SharePoint.

Here’s how to do this in Silverlight:

private void Update_Click(object sender, RoutedEventArgs e)
{
ClientContext ctx = new ClientContext(Your Server Here");
CamlQuery query = new CamlQuery();
query.ViewXml = "<View><Query><OrderBy>" +
"<FieldRef Name=\"Editor\" Ascending=\"False\" />" +
"</OrderBy></Query></View>";
List announcements = ctx.Web.Lists.GetByTitle("Announcements");
ListItemCollection listItems = announcements.GetItems(query);
ctx.Load(listItems);
ctx.ExecuteQueryAsync((s, args) =>
{
foreach (var item in listItems)
{
item["Title"] = "Updated";
item.Update();
}
ctx.ExecuteQueryAsync((s1, args1) =>
{
Dispatcher.BeginInvoke(() =>
{
label1.Content = "Records Updated";
});
}, null);
}, (s, args) =>
{
Dispatcher.BeginInvoke(() =>
{
label1.Content = args.Message;
});
});
}



And here it is in JavaScript:

function Update_Click() {
var ctx = new SP.ClientContext.get_current();
var query = new SP.CamlQuery();
query.viewXml = "<View><Query><OrderBy>" +
"<FieldRef Name=\"Editor\" Ascending=\"False\" />" +
"</OrderBy></Query></View>";
var announcements = ctx.get_web().get_lists().getByTitle("Announcements");
var listItems = announcements.getItems(query);
ctx.load(listItems, "Include(Title)");
ctx.executeQueryAsync(function (s, args) {
var itemEnum = listItems.getEnumerator();
while (itemEnum.moveNext()) {
var item = itemEnum.get_current();
item.set_item("Title","JavaScript Update");
item.update();
}
ctx.executeQueryAsync(function (s, args) {
var console = document.getElementById('DemoConsole');
console.innerHTML =" JavaScript Update Completed";
}, null);
}, null);
}



As you can see from these code samples, updating values from the Client Object Model works in a similar way to updating objects on the server, in that the Update method must be called to commit the changes.

Other  
  •  Sharepoint 2010 : Client Object Model - Retrieving Data
  •  Sharepoint 2010 : Client Object Model - Available Client-side Objects
  •  Sharepoint 2010 : Client Object Model - Architecture , Demonstration Environment Setup
  •  Developer Tools for SharePoint 2013 : Troubleshooting with Debugging
  •  Developer Tools for SharePoint 2013 : Setting Up Your Development Environment
  •  Developer Tools for SharePoint 2013 : Understanding Visual Studio 2012 Tools (part 3) - SharePoint Solutions
  •  Developer Tools for SharePoint 2013 : Understanding Visual Studio 2012 Tools (part 2) - Applications for SharePoint
  •  Developer Tools for SharePoint 2013 : Understanding Visual Studio 2012 Tools (part 1) - SharePoint Connections in Server Explorer
  •  Developer Tools for SharePoint 2013 : Understanding SharePoint Designer 2013
  •  Developer Tools for SharePoint 2013 : Customization Options with SharePoint , OOB Developer Experience
  •  
    Top 10
    Free Mobile And Desktop Apps For Accessing Restricted Websites
    MASERATI QUATTROPORTE; DIESEL : Lure of Italian limos
    TOYOTA CAMRY 2; 2.5 : Camry now more comely
    KIA SORENTO 2.2CRDi : Fuel-sipping slugger
    How To Setup, Password Protect & Encrypt Wireless Internet Connection
    Emulate And Run iPad Apps On Windows, Mac OS X & Linux With iPadian
    Backup & Restore Game Progress From Any Game With SaveGameProgress
    Generate A Facebook Timeline Cover Using A Free App
    New App for Women ‘Remix’ Offers Fashion Advice & Style Tips
    SG50 Ferrari F12berlinetta : Prancing Horse for Lion City's 50th
    - Messages forwarded by Outlook rule go nowhere
    - Create and Deploy Windows 7 Image
    - How do I check to see if my exchange 2003 is an open relay? (not using a open relay tester tool online, but on the console)
    - Creating and using an unencrypted cookie in ASP.NET
    - Directories
    - Poor Performance on Sharepoint 2010 Server
    - SBS 2008 ~ The e-mail alias already exists...
    - Public to Private IP - DNS Changes
    - Send Email from Winform application
    - How to create a .mdb file from ms sql server database.......
    programming4us programming4us
    programming4us
     
     
    programming4us