As I discussed my previous post the Client Object Model allows client application to interact with SharePoint content directly. The ADO.NET Data Services Framework helps to query SharePoint Foundation data via client application.
In this example you will see .NET Managed client by create Windows Form application, and you will see how to retrieve list items and updating the items via Client Object Model.
1. Open Visual Studio 2010 by going to the Start Menu | Programs | Microsoft Visual Studio 2010 | Microsoft Visual Studio 2010.
2. From the menu, select File | New | Project.
3. In the New Project dialog window, choose Visual C# | Windows from the Installed Templates.
4. Select Windows Forms Applications from the Project Templates.
5. Go to Visual Studio top menu bar, select Data | Add New Data Source… to add new SharePoint ADO.NET List Data Service.
6. In the Data Source Configuration Wizard select Service and click Next > button. When next screen appear Add Service Reference dialog window, type the following Url in the Address text box and click Go:
7. Click OK.
8. Click Finish button in the Data Source Configuration Wizard.
9. Go to Solution Explorer, expand References. and Right click on System.Data.Services.Client and select Remove.
10. Right click on References and select Add Reference and switch to Browse tab and type the following path in the File name textbox and press enter:
C:\Program Files (x86)\ADO.NET Data Services V1.5 CTP2
11. Select Microsoft.Data.Services.Client.dll.
12. Got Visual Studio Data menu and Click Show Data Source System will open the Data Sources window showing the service reference.
13. Drag and drop Tasks from the Data Sources window to the Form window. This will insert the Tasks DataGrid into the Form.
14. You can Remove columns by clicking Edit Columns window, Keep only following columns as shown in the screen shot.
15. Add the following using statement in the code behind:
- using SharePointADORESTService.ServiceReference1;
- using System.Net;
16. Insert the following code just after the Form1 class declaration:
17. Insert the following code in the Form1_Load method
- context.Credentials = CredentialCache.DefaultCredentials;
- tasksBindingSource.DataSource = context.Tasks;
18. To Update changes from Data Grid to go Tasks DataGrid, select the BindingNavigator right click on the Save button and Select Enable.
19. Double click on the Save button in the BindingNavigator to generate the Save method:
20. Go to TaskBindingSource –> Right Click –> and Go to Properties Select Events. Double click on CurrentItemChanged event. Visual Studio will generate the item changed event for the TasksBindingSource:
21. Press F5 to start debugging the application.
22. You should see the application window with the list of Tasks items from SharePoint List.
23. Click on the first tasks and change the Title value from Faizal from Rafi and click Save and go to SharePoint Tasks list you will able to view the updates.
For Source Code click here
Post a Comment