974 views(since 2013/10/08)

新規登録時にIDを取得する方法(Client Object Model, Sharepoint Online(Office365), Silverlight, C#)

新規登録時にIDを取得する方法

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using SP = Microsoft.SharePoint.Client;

using SilverlightProjectMain.Models.SharepointClient.Base;

namespace SilverlightProjectMain.Models.SharepointClient
{
    public class Adapter_CQuotation : Adapter_Base0100
    {
        //新規追加時にID取りたいのでこのスコープで宣言
        static private SP.ListItem _listItem = null;
        static public void Test()
        {
            using (var clientContext = new SP.ClientContext(SP.ApplicationContext.Current.Url))
            {
                var list = clientContext.Web.Lists.GetByTitle("List_Quotation");
                //clientContext.Load(list);

                _listItem = list.AddItem(new SP.ListItemCreationInformation());

                _listItem["InvoiceID"] = "AAAAAA";
                _listItem["CustomerName"] = "BBBBBB";

                _listItem.Update();

                //Load 不要
                //clientContext.Load(list, olist => olist.Title);

                clientContext.ExecuteQueryAsync(
                    new SP.ClientRequestSucceededEventHandler(delegate(object o, SP.ClientRequestSucceededEventArgs successargs)
                    {
                        int nID = _listItem.Id;
                    }),
                    new SP.ClientRequestFailedEventHandler(delegate(object o, SP.ClientRequestFailedEventArgs failedArgs)
                    {
                    })                );
            }
        }
    }
}

Filed Under: Office365 App

About the Author

野呂清二(ご連絡はこちらまで (http://www.exceedone.co.jp/inquiry/)

Leave a Reply




If you want a picture to show with your comment, go get a Gravatar.