当前位置: 首页>>代码示例>>C#>>正文


C# ListItemCreationInformation类代码示例

本文整理汇总了C#中ListItemCreationInformation的典型用法代码示例。如果您正苦于以下问题:C# ListItemCreationInformation类的具体用法?C# ListItemCreationInformation怎么用?C# ListItemCreationInformation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ListItemCreationInformation类属于命名空间,在下文中一共展示了ListItemCreationInformation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddDeptCal

        public bool AddDeptCal(SharePointContext spContext, string Title, string StartDates, string EndDates)
        {

            // using (var clientContext = TokenHelper.GetClientContextWithContextToken(sharepointUrl, contextToken, hostUrl))
            if (spContext == null)
                spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext.Current);
            using (var clientContext = spContext.CreateAppOnlyClientContextForSPHost()) //CreateAppOnlyClientContextForSPAppWeb
            {
                    try
                    {
                        ListCollection lists = clientContext.Web.Lists;
                        List selectedList = lists.GetByTitle("Department Calendar"); // Getting Listname from ConfigList
                        ListItemCreationInformation itemCreateInfo;
                        Microsoft.SharePoint.Client.ListItem newItem;
                        itemCreateInfo = new ListItemCreationInformation();
                        newItem = selectedList.AddItem(itemCreateInfo);
                        newItem["Title"] = Title;
                        newItem["EventDate"] = Convert.ToDateTime(StartDates);
                        newItem["EndDate"] = Convert.ToDateTime(EndDates);
                        newItem["Description"] = "";
                        newItem.Update();
                        clientContext.ExecuteQuery();
                        return true;
                    }
                    catch (Exception ex)
                    {
                        Microsoft.SharePoint.Client.Utilities.Utility.LogCustomRemoteAppError(clientContext, Global.ProductId, ex.Message);
                        clientContext.ExecuteQuery();
                        return false;
                    }
            }
        }
开发者ID:prashanthganathe,项目名称:PersonalProjects,代码行数:32,代码来源:DeptCalListClass.cs

示例2: AddSiteDirectoryEntry

        /// <summary>
        /// Adds a new entry to the site directory list
        /// </summary>
        /// <param name="siteDirectoryHost">Url to the site directory site collection</param>
        /// <param name="siteDirectoryProvisioningPage">Path to a page used as url when the site collection is not yet provisioned</param>
        /// <param name="listName">Name of the site directory list</param>
        /// <param name="title">Title of the site collection</param>
        /// <param name="siteUrl">Url of the site collection</param>
        /// <param name="template">Template used to provision this site collection</param>
        /// <param name="requestor">Person that requested the provisioning</param>
        /// <param name="owner">Person that will be the primary owner of the site collection</param>
        /// <param name="backupOwners">Person(s) that will be the backup owner(s) of the site collection</param>
        /// <param name="permissions">Chosen permission model</param>
        public void AddSiteDirectoryEntry(ClientContext cc, Web web, string siteDirectoryHost, string siteDirectoryProvisioningPage, string listName, string title, string siteUrl, string template, string[] ownerLogins)
        {
            List listToInsertTo = web.Lists.GetByTitle(listName);
            ListItemCreationInformation lici = new ListItemCreationInformation();
            ListItem listItem = listToInsertTo.AddItem(lici);
            listItem["Title"] = title;

            //URL = hyperlink field
            FieldUrlValue url = new FieldUrlValue();
            url.Description = title;
            url.Url = String.Format("{0}/{1}", siteDirectoryHost, siteDirectoryProvisioningPage);
            listItem["SiteTitle"] = url;
            // store url also as text field to facilitate easy CAML querying afterwards
            listItem["UrlText"] = siteUrl;

            // Owners = Person field with multiple values
            FieldUserValue[] users = new FieldUserValue[ownerLogins.Length];

            int i = 0;
            foreach (string ownerLogin in ownerLogins)
            {
                FieldUserValue ownersField = FieldUserValue.FromUser(ownerLogin);
                users[i] = ownersField;
                i++;
            }
            listItem["Owners"] = users;
            listItem["Template"] = template;
            listItem["Status"] = "Requested";
            listItem.Update();
            cc.ExecuteQuery();
        }
开发者ID:AaronSaikovski,项目名称:PnP,代码行数:44,代码来源:SiteDirectoryManager.cs

示例3: CreateSiteButton_Click

        protected void CreateSiteButton_Click(object sender, EventArgs e)
        {
            var spContext = SharePointContextProvider.Current.GetSharePointContext(Context);

            //using (var clientContext = spContext.CreateAppOnlyClientContextForSPAppWeb())
            using ( var clientContext = spContext.CreateUserClientContextForSPAppWeb())
            {
                var web = clientContext.Web;
                clientContext.Load(web);
                var list = web.Lists.GetByTitle("SiteCreationRequests");
                clientContext.Load(list);
                clientContext.ExecuteQuery();
                //var roleassignments = list.RoleAssignments;
                //clientContext.Load(roleassignments);
                //clientContext.ExecuteQuery();
                //clientContext.Load(roleassignments.Groups.GetById(3));
                //clientContext.Load(clientContext.Web.CurrentUser);
                //clientContext.ExecuteQuery();
                //var ownerGroup = roleassignments.Groups.GetById(3);
                //clientContext.Load(ownerGroup.Users);
                //clientContext.ExecuteQuery();
                //ownerGroup.Users.AddUser(clientContext.Web.CurrentUser);
                //ownerGroup.Update();
                //clientContext.ExecuteQuery();
                var newItemCreator = new ListItemCreationInformation();
                var newItem = list.AddItem(newItemCreator);
                newItem["Title"] = SiteName.Text;
                newItem["Approver"] = clientContext.Web.GetUserById(11);
                //newItem["Approver"] = clientContext.Web.CurrentUser;
                newItem["Approved"] = false;
                newItem.Update();
                clientContext.ExecuteQuery();
            }
        }
开发者ID:CherifSy,项目名称:PnP,代码行数:34,代码来源:Default.aspx.cs

示例4: SPtimer_Elapsed

        void SPtimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            //Comment out either of the below based on On Premise server or Online
               // Uri hostWeb = new Uri("http://tenant/sites/DevCenter");

            //Below line works with On line
            Uri hostWeb = new Uri("https://sweethome03.sharepoint.com");

            string realm = TokenHelper.GetRealmFromTargetUrl(hostWeb);

            string appOnlyAccessToken = TokenHelper.GetAppOnlyAccessToken(SharePointPrincipal, hostWeb.Authority, realm).AccessToken;

            using (ClientContext clientContext = TokenHelper.GetClientContextWithAccessToken(hostWeb.ToString(), appOnlyAccessToken))
            {
                if (clientContext != null)
                {
                    var myList = clientContext.Web.Lists.GetByTitle("WindowsTimerJob");
                    ListItemCreationInformation listItemCreate = new ListItemCreationInformation();
                    Microsoft.SharePoint.Client.ListItem newItem = myList.AddItem(listItemCreate);
                    newItem["Title"] = "Added from Timer Job";
                    newItem.Update();
                    clientContext.ExecuteQuery();
                }
            }
        }
开发者ID:bayzid026,项目名称:mvc,代码行数:25,代码来源:Service1.cs

示例5: TraceData

		public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data)
		{
			if (data is LogEntity)
			{
				using (DocLibContext clientContext = new DocLibContext())
				{
					MossServerInfoConfigurationSettings section =
						MossServerInfoConfigurationSettings.GetConfig();

					MossServerInfoConfigurationElement document = section.Servers["documentServer"];
					if (document != null)
					{
						ListCollection lists = clientContext.Web.Lists;
						clientContext.Load(lists);
						List logList = lists.GetByTitle(document.LogListName);
						clientContext.Load(logList);
						clientContext.ExecuteQuery();
						ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
						ListItem oListItem = logList.AddItem(itemCreateInfo);
						oListItem["Title"] = ((LogEntity)data).Title;
						oListItem["operationInfo"] = ((LogEntity)data).Message;
						oListItem.Update();
						//clientContext.Load(itemCreateInfo);
						clientContext.ExecuteQuery();
					}

				}
			}
			else
			{
				base.TraceData(eventCache, source, eventType, id, data);
			}
		}
开发者ID:jerryshi2007,项目名称:AK47Source,代码行数:33,代码来源:Logger.cs

示例6: DumpErrorIntoAppLog

        //public TValue ErrorHandler<TValue>(Func<TValue> action)
        //{
        //    try
        //    {
        //        return action();
        //    }
        //    catch (Exception ex)
        //    {
        //        DumpErrorIntoAppLog(DateTime.Now.ToString(CultureInfo.InvariantCulture), ex.Message);
        //        return default(TValue);
        //    }
        //}

        //public void ErrorHandler(Action action)
        //{
        //    try
        //    {
        //        action();
        //    }
        //    catch (Exception ex)
        //    {
        //        DumpErrorIntoAppLog(DateTime.Now.ToString(CultureInfo.InvariantCulture), ex.Message);
        //    }
        //}


        public void DumpErrorIntoAppLog(string time, string message)
        {
            ContextUtility utility = new ContextUtility(HttpContext.Current.Request);
            using (ClientContext context = TokenHelper.GetClientContextWithContextToken(utility.ContextDetails.AppWebUrl, utility.ContextDetails.ContextTokenString, HttpContext.Current.Request.Url.Authority))
            {
                try
                {
                    List list = context.Web.Lists.GetByTitle("Errors");
                    context.Load(list);
                    context.ExecuteQuery();
                    if (list == null)
                    {
                        return;
                    }
                    CamlQuery query = CamlQuery.CreateAllItemsQuery();
                    ListItemCollection items = list.GetItems(query);
                    context.Load(items);
                    context.ExecuteQuery();

                    Microsoft.SharePoint.Client.ListItem newItem;
                    ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                    newItem = list.AddItem(itemCreateInfo);
                    newItem["Errors"] = string.Format("Time: {0} Message: {1}", time, message);
                    newItem.Update();
                    context.ExecuteQuery();
                }
                catch (Exception ex)
                {
                    Microsoft.SharePoint.Client.Utilities.Utility.LogCustomRemoteAppError(context, Global.ProductId, ex.Message);
                    context.ExecuteQuery();
                }
            }
        }
开发者ID:prashanthganathe,项目名称:PersonalProjects,代码行数:59,代码来源:CustomException.cs

示例7: AddProduct

        public static bool AddProduct(SharePointContext spContext, Product product)
        {
            using (var clientContext = spContext.CreateUserClientContextForSPAppWeb())
            {
                if (clientContext != null)
                {
                    try
                    {
                        List lstProducts = clientContext.Web.Lists.GetByTitle("Products");

                        ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                        ListItem newProduct = lstProducts.AddItem(itemCreateInfo);
                        newProduct["Title"] = product.Title;
                        newProduct["ProductDescription"] = product.Description;
                        newProduct["Price"] = product.Price;
                        newProduct.Update();

                        clientContext.ExecuteQuery();

                        return true;
                    }
                    catch (ServerException ex)
                    {
                        return false;
                    }
                }
            }

            return false;
        }
开发者ID:neferterijumawan,项目名称:Product-List-Code-Sample,代码行数:30,代码来源:SharePointService.cs

示例8: SendMonitoringData

        public void SendMonitoringData(int UniqueID, string type, double value)
        {
            // Get access to source site
            using (var ctx = new ClientContext(tenant))
            {
                //Provide count and pwd for connecting to the source
                var passWord = new SecureString();
                foreach (char c in passwordString.ToCharArray()) passWord.AppendChar(c);
                ctx.Credentials = new SharePointOnlineCredentials(userName, passWord);
                // Actual code for operations
                Web web = ctx.Web;
                ctx.Load(web);
                ctx.ExecuteQuery();

                List myList = web.Lists.GetByTitle("MonitorLiveData");

                ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                ListItem newItem = myList.AddItem(itemCreateInfo);
                newItem["AlertID"] = UniqueID.ToString();
                newItem["DataType"] = type.ToString();
                newItem["DataValue"] = value;
                newItem.Update();

                ctx.ExecuteQuery();
            }
        }
开发者ID:Inmeta,项目名称:aspc2016,代码行数:26,代码来源:Service1.svc.cs

示例9: FillHostWebSupportCasesToThreshold

        public string FillHostWebSupportCasesToThreshold()
        {
            using (var clientContext = SharePointContext.CreateUserClientContextForSPHost())
            {
                List supportCasesList = clientContext.Web.Lists.GetByTitle("Support Cases");
                ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                for (int i = 0; i < 500; i++)
                {
                    ListItem newItem = supportCasesList.AddItem(itemCreateInfo);
                    newItem["Title"] = "Wrong product received." + i.ToString();
                    newItem["FTCAM_Status"] = "Open";
                    newItem["FTCAM_CSR"] = "bjones";
                    newItem["FTCAM_CustomerID"] = "thresholds test";
                    newItem.Update();
                    if (i % 100 == 0)
                        clientContext.ExecuteQuery();
                }
                clientContext.ExecuteQuery();

               
                clientContext.Load(supportCasesList, l => l.ItemCount);
                clientContext.ExecuteQuery();

                if(supportCasesList.ItemCount>=5000)
                    return "The Host Web Support Cases List has " + supportCasesList.ItemCount + " items, and exceeds the threshold.";
                else
                    return 500 + " items have been added to the Host Web Support Cases List. " +
                     "There are " + (5000 - supportCasesList.ItemCount) + " items left to add.";    
            }
        }
开发者ID:NicolajLarsen,项目名称:PnP,代码行数:30,代码来源:SharePointService.cs

示例10: Main

        /// <summary>
        /// 
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            Uri siteUri = new Uri(ConfigurationManager.AppSettings["url"]);

            //Get the realm for the URL
            string realm = TokenHelper.GetRealmFromTargetUrl(siteUri);

            //Get the access token for the URL.  
            //   Requires this app to be registered with the tenant
            string accessToken = TokenHelper.GetAppOnlyAccessToken(
                TokenHelper.SharePointPrincipal,
                siteUri.Authority, realm).AccessToken;

            //Get client context with access token
            using (var ctx =
                TokenHelper.GetClientContextWithAccessToken(
                    siteUri.ToString(), accessToken))
            {
                // Let's create a list to the host web and add a new entry for each execution
                if (!ListExists(ctx.Web, "RemoteOperation"))
                {
                    AddList(ctx.Web, ListTemplateType.GenericList, "RemoteOperation");
                }

                // Add new execution entry to the list time stamp
                // Assume that the web has a list named "Announcements". 
                List list = ctx.Web.Lists.GetByTitle("RemoteOperation");
                ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                ListItem newItem = list.AddItem(itemCreateInfo);
                newItem["Title"] = string.Format("New {0}", DateTime.Now.ToLongTimeString());
                newItem.Update();

                ctx.ExecuteQuery();
            }
        }
开发者ID:chrissimusokwe,项目名称:TrainingContent,代码行数:39,代码来源:Program.cs

示例11: FillAppWebNotesListToThreshold

        public string FillAppWebNotesListToThreshold()
        {
            using (var clientContext = SharePointContext.CreateUserClientContextForSPAppWeb())
            {
                List notesList = clientContext.Web.Lists.GetByTitle("Notes");

                var itemCreateInfo = new ListItemCreationInformation();
                for (int i = 0; i < 500; i++)
                {
                    ListItem newItem = notesList.AddItem(itemCreateInfo);
                    newItem["Title"] = "Notes Title." + i.ToString();
                    newItem["FTCAM_Description"] = "Notes description";
                    newItem.Update();
                    if (i % 100 == 0)
                        clientContext.ExecuteQuery();
                }
                clientContext.ExecuteQuery();

                clientContext.Load(notesList, l => l.ItemCount);
                clientContext.ExecuteQuery();

                if (notesList.ItemCount >= 5000)
                    return "The App Web Notes List has " + notesList.ItemCount + " items, and exceeds the threshold.";
                else
                    return 500 + " items have been added to the App Web Notes List. " +
                                   "There are " + (5000-notesList.ItemCount) + " items left to add.";          
            }
        }
开发者ID:NicolajLarsen,项目名称:PnP,代码行数:28,代码来源:SharePointService.cs

示例12: CreateNewRequest

        private int CreateNewRequest(string siteName, string siteTitle, string siteDescription, string[] owners, string[] members, string[] visitors)
        {
            // Get the term foeld for the Reasearch taxonomy
            var termfield = _siteRequestList.Fields.GetByInternalNameOrTitle("InstitutionalSiteClassification");
            _sharePoint.ClientContext.Load(termfield);
            _sharePoint.ClientContext.ExecuteQuery();

            const string term = "Research";

            string hiddentextFieldId = string.Empty;
            string termId = SharePointTaxonomyHelper.GetTermInfo(_sharePoint.Root, termfield, term, ref hiddentextFieldId);

            Field hiddenTextField = _siteRequestList.Fields.GetById(new Guid(hiddentextFieldId));
            _sharePoint.ClientContext.Load(hiddenTextField);
            _sharePoint.ClientContext.ExecuteQuery();

            var itemCreateInfo = new ListItemCreationInformation();
            var listItem = _siteRequestList.AddItem(itemCreateInfo);
            listItem["UrdmsSiteTitle"] = siteTitle;
            listItem["UrdmsSiteId"] = siteName;
            listItem["Body"] = siteDescription;
            listItem["UrdmsSiteProvisioningRequestStatus"] = "Approved";
            listItem["UrdmsClassification"] = String.Format("-1;#{0}|{1}", term, termId);
            listItem[hiddenTextField.InternalName] = String.Format("-1;#{0}|{1}", term, termId);
            // Set Site Users
            listItem["UrdmsSiteOwners"] = SetUserValues(owners);
            listItem["UrdmsSiteMembers"] = SetUserValues(members);
            listItem["UrdmsSiteVisitors"] = SetUserValues(visitors);

            listItem.Update();
            _sharePoint.ClientContext.ExecuteQuery();

            return listItem.Id;
        }
开发者ID:SharePointSusan,项目名称:Research-Data-Manager,代码行数:34,代码来源:SiteCreationRequestHelper.cs

示例13: cmdCreateCustomersList_Click

        protected void cmdCreateCustomersList_Click(object sender, EventArgs e)
        {
            SharePointContext spContext = SharePointContextProvider.Current.GetSharePointContext(Context);

              using (ClientContext clientContext = spContext.CreateUserClientContextForSPHost()) {

            clientContext.Load(clientContext.Web);
            clientContext.ExecuteQuery();
            string listTitle = "Customers";

            // delete list if it exists
            ExceptionHandlingScope scope = new ExceptionHandlingScope(clientContext);
            using (scope.StartScope()) {
              using (scope.StartTry()) {
            clientContext.Web.Lists.GetByTitle(listTitle).DeleteObject();
              }
              using (scope.StartCatch()) { }
            }

            // create and initialize ListCreationInformation object
            ListCreationInformation listInformation = new ListCreationInformation();
            listInformation.Title = listTitle;
            listInformation.Url = "Lists/Customers";
            listInformation.QuickLaunchOption = QuickLaunchOptions.On;
            listInformation.TemplateType = (int)ListTemplateType.Contacts;

            // Add ListCreationInformation to lists collection and return list object
            List list = clientContext.Web.Lists.Add(listInformation);

            // modify additional list properties and update
            list.OnQuickLaunch = true;
            list.EnableAttachments = false;
            list.Update();

            // send command to server to create list
            clientContext.ExecuteQuery();

            // add an item to the list
            ListItemCreationInformation lici1 = new ListItemCreationInformation();
            var item1 = list.AddItem(lici1);
            item1["Title"] = "Lennon";
            item1["FirstName"] = "John";
            item1.Update();

            // add a second item
            ListItemCreationInformation lici2 = new ListItemCreationInformation();
            var item2 = list.AddItem(lici2);
            item2["Title"] = "McCartney";
            item2["FirstName"] = "Paul";
            item2.Update();

            // send add commands to server
            clientContext.ExecuteQuery();

            // add message to app’s start page
            placeholderMainContent.Text = "New list created";

              }
        }
开发者ID:kimberpjub,项目名称:GSA2013,代码行数:59,代码来源:Default.aspx.cs

示例14: btnSave_Click

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string errMsg = string.Empty;

            try
            {
                using (var clientContext = GetClientContext())
                {
                    var web = GetClientContextWeb(clientContext);

                    var lstEmployee = web.Lists.GetByTitle("Employees");
                    var itemCreateInfo = new ListItemCreationInformation();
                    var listItem = lstEmployee.AddItem(itemCreateInfo);

                    listItem["EmpNumber"] = txtEmpNumber.Text;
                    listItem["UserID"] = txtUserID.Text;
                    listItem["Title"] = txtName.Text;
                    listItem["EmpManager"] = txtManager.Text;
                    listItem["Designation"] = ddlDesignation.SelectedValue;
                    listItem["Location"] = ddlCity.Text;

                    StringBuilder sbSkills = new StringBuilder();
                    RepeaterItemCollection skills = rptSkills.Items;
                    foreach (RepeaterItem skill in skills)
                    {
                        TextBox tbTech = (TextBox)skill.FindControl("rptTxtTechnology");
                        TextBox tbSkill = (TextBox)skill.FindControl("rptTxtExperience");
                        sbSkills.Append(tbTech.Text).Append(",").Append(tbSkill.Text).Append(";");
                    }
                    listItem["Skills"] = sbSkills.ToString();

                    if (rptUploadedFiles.Items.Count > 0)
                    {
                        listItem["AttachmentID"] = hdnAttachmentID.Value;
                    }

                    listItem.Update();
                    clientContext.ExecuteQuery();
                }
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
            }

            if (errMsg.Length > 0)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "errorMessage", "alert('" + errMsg + "');", true);
            }
            else
            {
                string url = HttpContext.Current.Request.Url.AbsoluteUri;
                url = url.Replace("Default.aspx", "Thanks.aspx");
                Response.Redirect(url);
            }
        }
开发者ID:briankinsella,项目名称:PnP-Transformation,代码行数:56,代码来源:Default.aspx.cs

示例15: AddListItem

 private static void AddListItem(ClientContext clientContext, string listName)
 {
     Web currentWeb = clientContext.Web;
     var myList = clientContext.Web.Lists.GetByTitle(listName);
     ListItemCreationInformation listItemCreate = new ListItemCreationInformation();
     Microsoft.SharePoint.Client.ListItem newItem = myList.AddItem(listItemCreate);
     newItem["Title"] = "Item added by Job at " + DateTime.Now;
     newItem.Update();
     clientContext.ExecuteQuery();
 }
开发者ID:bayzid026,项目名称:mvc,代码行数:10,代码来源:Program.cs


注:本文中的ListItemCreationInformation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。