static void CreateWingtipSiteColumns() { Console.WriteLine(); fieldProductCode = CreateSiteColumn("ProductCode", "Product Code", "Text"); fieldProductCode.EnforceUniqueValues = true; fieldProductCode.Indexed = true; fieldProductCode.Required = true; fieldProductCode.Update(); clientContext.ExecuteQuery(); clientContext.Load(fieldProductCode); clientContext.ExecuteQuery(); fieldProductDescription = clientContext.CastTo <FieldMultiLineText>(CreateSiteColumn("ProductDescription", "Product Description", "Note")); fieldProductDescription.NumberOfLines = 4; fieldProductDescription.RichText = false; fieldProductDescription.Update(); clientContext.ExecuteQuery(); fieldProductListPrice = clientContext.CastTo <FieldCurrency>(CreateSiteColumn("ProductListPrice", "List Price", "Currency")); fieldProductListPrice.MinimumValue = 0; fieldProductListPrice.Update(); clientContext.ExecuteQuery(); fieldProductColor = clientContext.CastTo <FieldMultiChoice>(CreateSiteColumn("ProductColor", "Product Color", "MultiChoice")); string[] choicesProductColor = { "White", "Black", "Grey", "Blue", "Red", "Green", "Yellow" }; fieldProductColor.Choices = choicesProductColor; fieldProductColor.Update(); clientContext.ExecuteQuery(); fieldMinimumAge = clientContext.CastTo <FieldNumber>(CreateSiteColumn("MinimumAge", "Minimum Age", "Number")); fieldMinimumAge.MinimumValue = 1; fieldMinimumAge.MaximumValue = 100; fieldMinimumAge.Update(); clientContext.ExecuteQuery(); fieldMaximumAge = clientContext.CastTo <FieldNumber>(CreateSiteColumn("MaximumAge", "Maximum Age", "Number")); fieldMaximumAge.MinimumValue = 1; fieldMaximumAge.MaximumValue = 100; fieldMaximumAge.Update(); clientContext.ExecuteQuery(); fieldProductImageUrl = clientContext.CastTo <FieldUrl>(CreateSiteColumn("ProductImageUrl", "Product Image Url", "URL")); fieldProductImageUrl.DisplayFormat = UrlFieldFormatType.Image; fieldProductImageUrl.Update(); clientContext.ExecuteQuery(); }
static void CreateWingtipDocumentSiteColumns() { Console.WriteLine(); Console.WriteLine("Executing CreateWingtipDocumentSiteColumns()..."); try { fieldProductImageUrl = clientContext.CastTo<FieldUrl>(CreateSiteColumn("ProductImageUrl", "Product Image Url", "URL")); fieldProductImageUrl.DisplayFormat = UrlFieldFormatType.Image; fieldProductImageUrl.Update(); clientContext.ExecuteQuery(); } catch { } }
static void CreateWingtipSiteColumns() { Console.WriteLine(); fieldProductCode = CreateSiteColumn("ProductCode", "Product Code", "Text"); fieldProductCode.EnforceUniqueValues = true; fieldProductCode.Indexed = true; fieldProductCode.Required = true; fieldProductCode.Update(); clientContext.ExecuteQuery(); clientContext.Load(fieldProductCode); clientContext.ExecuteQuery(); fieldProductDescription = clientContext.CastTo<FieldMultiLineText>(CreateSiteColumn("ProductDescription", "Product Description", "Note")); fieldProductDescription.NumberOfLines = 4; fieldProductDescription.RichText = false; fieldProductDescription.Update(); clientContext.ExecuteQuery(); fieldProductListPrice = clientContext.CastTo<FieldCurrency>(CreateSiteColumn("ProductListPrice", "List Price", "Currency")); fieldProductListPrice.MinimumValue = 0; fieldProductListPrice.Update(); clientContext.ExecuteQuery(); fieldProductCategory = clientContext.CastTo<TaxonomyField>(CreateSiteColumn("ProductCategory", "Product Category", "TaxonomyFieldType")); fieldProductCategory.SspId = localTermStoreID; fieldProductCategory.TermSetId = termSetId; fieldProductCategory.AllowMultipleValues = false; fieldProductCategory.Update(); clientContext.ExecuteQuery(); fieldProductColor = clientContext.CastTo<FieldMultiChoice>(CreateSiteColumn("ProductColor", "Product Color", "MultiChoice")); string[] choicesProductColor = { "White", "Black", "Grey", "Blue", "Red", "Green", "Yellow" }; fieldProductColor.Choices = choicesProductColor; fieldProductColor.Update(); clientContext.ExecuteQuery(); fieldMinimumAge = clientContext.CastTo<FieldNumber>(CreateSiteColumn("MinimumAge", "Minimum Age", "Number")); fieldMinimumAge.MinimumValue = 1; fieldMinimumAge.MaximumValue = 100; fieldMinimumAge.Update(); clientContext.ExecuteQuery(); fieldMaximumAge = clientContext.CastTo<FieldNumber>(CreateSiteColumn("MaximumAge", "Maximum Age", "Number")); fieldMaximumAge.MinimumValue = 1; fieldMaximumAge.MaximumValue = 100; fieldMaximumAge.Update(); clientContext.ExecuteQuery(); fieldProductImageUrl = clientContext.CastTo<FieldUrl>(CreateSiteColumn("ProductImageUrl", "Product Image Url", "URL")); fieldProductImageUrl.DisplayFormat = UrlFieldFormatType.Image; fieldProductImageUrl.Update(); clientContext.ExecuteQuery(); }
public static void CreateCV(ClientContext ctx) { string cVCT = "0x010100A959F697950047DF80D85119D99F8CA7"; Web web = ctx.Site.RootWeb; if (!web.ContentTypeExistsById(cVCT)) { web.CreateContentType("CV", cVCT, "Davids ContentType"); } string picFieldId = "{98A1C95C-AA0F-4D2C-92C8-5407594C440F}"; if (!web.FieldExistsById(new Guid(picFieldId))) { FieldCreationInformation info = new FieldCreationInformation(FieldType.URL); info.Id = picFieldId.ToGuid(); info.InternalName = "DAV_Pic"; info.DisplayName = "Picture"; info.Group = "Tims Columns"; FieldUrl picfield = web.CreateField <FieldUrl>(info); picfield.DisplayFormat = UrlFieldFormatType.Image; picfield.Update(); ctx.ExecuteQuery(); } string userFieldId = "{B0C1EFC4-189E-4626-A1DC-1CCC4693C097}"; if (!web.FieldExistsById(new Guid(userFieldId))) { FieldCreationInformation info = new FieldCreationInformation(FieldType.User); info.Id = userFieldId.ToGuid(); info.InternalName = "DAV_User"; info.DisplayName = "User"; info.Group = "Tims Columns"; FieldUser userfield = web.CreateField <FieldUser>(info); ctx.ExecuteQuery(); } string activeFieldId = "{2CB24A28-3F5B-49AE-9F54-5FD8747DBF19}"; if (!web.FieldExistsById(new Guid(activeFieldId))) { FieldCreationInformation info = new FieldCreationInformation(FieldType.Boolean); info.Id = activeFieldId.ToGuid(); info.InternalName = "DAV_Active"; info.DisplayName = "Active"; info.Group = "Tims Columns"; web.CreateField(info); } web.AddFieldToContentTypeById(cVCT, picFieldId); web.AddFieldToContentTypeById(cVCT, userFieldId); web.AddFieldToContentTypeById(cVCT, activeFieldId); if (!web.ListExists("CVs")) { List list = web.CreateList(ListTemplateType.DocumentLibrary, "CVs", true, enableContentTypes: true); list.AddContentTypeToListById(cVCT); } List CVList = web.GetListByTitle("CVs"); FileCreationInformation fileinfo = new FileCreationInformation(); System.IO.FileStream fileStream = System.IO.File.OpenRead(@"C:\Users\timha\source\repos\Officedeveloper1\ContentTypesAndFields\ContentTypesAndFields\TextFile1.txt"); fileinfo.Content = ReadFully(fileStream); fileinfo.Url = "file1.txt"; Microsoft.SharePoint.Client.File files = CVList.RootFolder.Files.Add(fileinfo); ctx.ExecuteQuery(); User user = web.EnsureUser("*****@*****.**"); ctx.Load(user); ctx.ExecuteQuery(); ListItem item = files.ListItemAllFields; item["Title"] = "Tim"; item["ContentTypeId"] = cVCT; FieldUrlValue picvalue = new FieldUrlValue(); picvalue.Description = "Tim"; picvalue.Url = "https://images.pexels.com/photos/104827/cat-pet-animal-domestic-104827.jpeg?w=940&h=650&auto=compress&cs=tinysrgb"; item["DAV_Pic"] = picvalue; item["DAV_User"] = user.Id; item["DAV_Active"] = true; item.Update(); ctx.ExecuteQuery(); }