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(); }
private static void CreateFields(ClientContext ctx, ContentType orderCT) { #region Customer FieldCreationInformation customer = new FieldCreationInformation(FieldType.Lookup); customer.DisplayName = "Customer"; customer.InternalName = "Customer"; customer.Group = "ODA1"; customer.Id = Constants.GUID.OrderCT.CUSTOMER.ToGuid(); ctx.Web.AddFieldToContentType(orderCT, ctx.Web.CreateField <FieldUrl>(customer, false)); #endregion #region Product TaxonomyFieldCreationInformation product = new TaxonomyFieldCreationInformation(); product.DisplayName = "Product"; product.InternalName = "Product_2"; product.Group = "ODA1"; product.TaxonomyItem = GetProductTermSet(ctx); product.Id = Constants.GUID.OrderCT.PRODUCT.ToGuid(); var meh = ctx.Web.CreateTaxonomyField(product); ctx.ExecuteQuery(); ctx.Web.WireUpTaxonomyField(meh, product.TaxonomyItem as TermSet); ctx.Web.AddFieldToContentType(orderCT, meh); #endregion #region Price FieldCreationInformation price = new FieldCreationInformation(FieldType.Currency); price.DisplayName = "Price"; price.InternalName = "Price"; price.Group = "ODA1"; price.Id = Constants.GUID.OrderCT.PRICE.ToGuid(); FieldUrl addedPrice = ctx.Web.CreateField <FieldUrl>(price, false); ctx.Web.AddFieldToContentType(orderCT, addedPrice); #endregion }
private static void CreateFields(ClientContext ctx, ContentType customerCT) { #region Customer logo FieldCreationInformation customerLogo = new FieldCreationInformation(FieldType.URL); customerLogo.DisplayName = "Logo"; customerLogo.InternalName = "DispLogo"; customerLogo.Group = "ODA1"; customerLogo.Id = Constants.GUID.CustomerCT.CUSTOMER_LOGO.ToGuid(); FieldUrl AddedCLOGO = ctx.Web.CreateField <FieldUrl>(customerLogo, false); //AddedCLOGO.DisplayFormat = UrlFieldFormatType.Image; //AddedCLOGO.Update(); ctx.ExecuteQuery(); ctx.Web.AddFieldToContentType(customerCT, AddedCLOGO); #endregion #region Address FieldCreationInformation address = new FieldCreationInformation(FieldType.Text); address.DisplayName = "Address"; address.InternalName = "Address"; address.Group = "ODA1"; address.Id = Constants.GUID.CustomerCT.ADDRESS.ToGuid(); ctx.Web.AddFieldToContentType(customerCT, ctx.Web.CreateField(address)); #endregion #region Main Contact Person FieldCreationInformation contactPerson = new FieldCreationInformation(FieldType.Text); contactPerson.DisplayName = "Contact Person"; contactPerson.InternalName = "contactPerson"; contactPerson.Group = "ODA1"; contactPerson.Id = Constants.GUID.CustomerCT.MAIN_CONTACT_PERSON.ToGuid(); ctx.Web.AddFieldToContentType(customerCT, ctx.Web.CreateField(contactPerson)); #endregion #region Office Phone FieldCreationInformation phoneOffice = new FieldCreationInformation(FieldType.Text); phoneOffice.DisplayName = "Office Phone"; phoneOffice.InternalName = "phoneOffice"; phoneOffice.Group = "ODA1"; phoneOffice.Id = Constants.GUID.CustomerCT.PHONE_OFFICE.ToGuid(); ctx.Web.AddFieldToContentType(customerCT, ctx.Web.CreateField(phoneOffice)); #endregion #region Mobile Phone FieldCreationInformation phoneMobile = new FieldCreationInformation(FieldType.Text); phoneMobile.DisplayName = "Mobile"; phoneMobile.InternalName = "phoneMobile"; phoneMobile.Group = "ODA1"; phoneMobile.Id = Constants.GUID.CustomerCT.PHONE_MOBILE.ToGuid(); ctx.Web.AddFieldToContentType(customerCT, ctx.Web.CreateField(phoneMobile)); #endregion #region Email FieldCreationInformation email = new FieldCreationInformation(FieldType.Text); email.DisplayName = "E-Mail"; email.InternalName = "Email"; email.Group = "ODA1"; email.Id = Constants.GUID.CustomerCT.EMAIL.ToGuid(); ctx.Web.AddFieldToContentType(customerCT, ctx.Web.CreateField(email)); #endregion #region Last Contacted (Date) FieldCreationInformation lastContacted = new FieldCreationInformation(FieldType.DateTime); lastContacted.DisplayName = "Last Contacted"; lastContacted.InternalName = "LastContacted"; lastContacted.Group = "ODA1"; lastContacted.Id = Constants.GUID.CustomerCT.LAST_CONTACTED.ToGuid(); ctx.Web.AddFieldToContentType(customerCT, ctx.Web.CreateField(lastContacted)); #endregion #region Last Order Made(Date, Read Only) FieldCreationInformation lastOrderMade = new FieldCreationInformation(FieldType.DateTime); lastOrderMade.DisplayName = "Last order made"; lastOrderMade.InternalName = "LastOrderMade"; lastOrderMade.Group = "ODA1"; lastOrderMade.Id = Constants.GUID.CustomerCT.LAST_ORDER_MADE.ToGuid(); FieldDateTime addedLastOderMade = ctx.Web.CreateField <FieldDateTime>(lastOrderMade, false); addedLastOderMade.ReadOnlyField = true; addedLastOderMade.Update(); ctx.ExecuteQuery(); ctx.Web.AddFieldToContentType(customerCT, addedLastOderMade); #endregion }
public static string GetDisplayFormat(this FieldUrl field) { return(field.DisplayFormat.ToString()); }
public FieldUrlInformation(FieldUrl field) : base(field) { Format = (uint)field.DisplayFormat; }
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(); }
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 { } }
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(); }