static void CreateExpenseSiteColumns() { fldExpenseCategory = clientContext.CastTo <FieldChoice>(CreateSiteColumn("ExpenseCategory", "Expense Category", "Choice")); string[] choicesExpenseCategory = ExpenseCategory.GetAll(); fldExpenseCategory.Choices = choicesExpenseCategory; fldExpenseCategory.Update(); clientContext.ExecuteQuery(); fldExpenseDate = clientContext.CastTo <FieldDateTime>(CreateSiteColumn("ExpenseDate", "Expense Date", "DateTime"));; fldExpenseDate.DisplayFormat = DateTimeFieldFormatType.DateOnly; fldExpenseDate.Update(); fldExpenseAmount = clientContext.CastTo <FieldCurrency>(CreateSiteColumn("ExpenseAmount", "Expense Amount", "Currency")); fldExpenseAmount.MinimumValue = 0; fldExpenseBudgetYear = clientContext.CastTo <FieldText>(CreateSiteColumn("ExpenseBudgetYear", "Budget Year", "Text")); fldExpenseBudgetQuarter = clientContext.CastTo <FieldText>(CreateSiteColumn("ExpenseBudgetQuarter", "Budget Quarter", "Text")); fldExpenseBudgetQuarter.Update(); fldExpenseBudgetAmount = clientContext.CastTo <FieldCurrency>(CreateSiteColumn("ExpenseBudgetAmount", "Budget Amount", "Currency")); clientContext.ExecuteQuery(); }
private FieldBase GetField(ContractPropertyInfo property) { FieldBase field = null; if (property.IsDictionary) { if (property.TypeName == "TranslatedStringDictionary") { field = new FieldTranslatedString { Required = false, Fixed = false, Index = true, SimpleSearch = true, MultiLine = false, Boost = 1, Analyzers = new List <AnalyzerBase> { new LanguageAnalyzer { SimpleSearch = true } } }; } else if (property.IsArray) { field = new FieldDictionaryArray(); } else { field = new FieldDictionary(); } } else if (property.IsEnum) { Type enumType = Type.GetType($"{property.FullName}, {property.AssemblyFullName}"); // TODO: Handle enums } else if (property.IsSimpleType) { if (!Enum.TryParse(property.TypeName, out TypeCode typeCode)) { throw new Exception($"Parsing to TypeCode enumarated object failed for string value: {property.TypeName}."); } if (property.IsArray) { switch (typeCode) { case TypeCode.String: field = new FieldStringArray { Index = true }; break; case TypeCode.DateTime: field = new FieldDateTimeArray { Index = true }; break; case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: field = new FieldLongArray { Index = true }; break; default: throw new Exception($"TypeCode {typeCode} is not supported."); } } else { var stringInfos = property.PictureparkAttributes.OfType <PictureparkStringAttribute>().SingleOrDefault(); switch (typeCode) { case TypeCode.String: field = new FieldString { Index = true, SimpleSearch = true, Boost = 1, Analyzers = new List <AnalyzerBase> { new SimpleAnalyzer { SimpleSearch = true } }, MultiLine = stringInfos?.MultiLine ?? false }; break; case TypeCode.DateTime: field = new FieldDateTime { Index = true }; break; case TypeCode.Boolean: field = new FieldBoolean { Index = true }; break; case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: field = new FieldLong { Index = true }; break; case TypeCode.Decimal: case TypeCode.Double: case TypeCode.Single: field = new FieldDecimal { Index = true }; break; default: throw new Exception($"TypeCode {typeCode} is not supported."); } } } else { var schemaIndexingAttribute = property.PictureparkAttributes.OfType <PictureparkSchemaIndexingAttribute>().SingleOrDefault(); var listItemCreateTemplateAttribute = property.PictureparkAttributes.OfType <PictureparkListItemCreateTemplateAttribute>().SingleOrDefault(); var maximumRecursionAttribute = property.PictureparkAttributes.OfType <PictureparkMaximumRecursionAttribute>().SingleOrDefault(); var tagboxAttributes = property.PictureparkAttributes.OfType <PictureparkTagboxAttribute>().SingleOrDefault(); var contentRelationAttributes = property.PictureparkAttributes.OfType <PictureparkContentRelationAttribute>().ToList(); var relationTypes = new List <RelationType>(); if (contentRelationAttributes.Any()) { relationTypes = contentRelationAttributes.Select(i => new RelationType { Id = i.Name, Filter = i.Filter, TargetDocType = i.TargetDocType, Names = new TranslatedStringDictionary { { "x-default", i.Name } } }).ToList(); } if (property.IsArray) { if (contentRelationAttributes.Any()) { field = new FieldMultiRelation { Index = true, RelationTypes = relationTypes, SchemaId = property.TypeName, SchemaIndexingInfo = schemaIndexingAttribute?.SchemaIndexingInfo }; } else if (property.IsReference) { field = new FieldMultiTagbox { Index = true, SimpleSearch = true, SchemaId = property.TypeName, Filter = tagboxAttributes?.Filter, SchemaIndexingInfo = schemaIndexingAttribute?.SchemaIndexingInfo, ListItemCreateTemplate = listItemCreateTemplateAttribute?.ListItemCreateTemplate }; } else { field = new FieldMultiFieldset { Index = true, SimpleSearch = true, SchemaId = property.TypeName, SchemaIndexingInfo = schemaIndexingAttribute?.SchemaIndexingInfo }; } } else { if (contentRelationAttributes.Any()) { field = new FieldSingleRelation { Index = true, SimpleSearch = true, RelationTypes = relationTypes, SchemaId = property.TypeName, SchemaIndexingInfo = schemaIndexingAttribute?.SchemaIndexingInfo }; } else if (property.TypeName == "GeoPoint") { field = new FieldGeoPoint { Index = true }; } else if (property.IsReference) { field = new FieldSingleTagbox { Index = true, SimpleSearch = true, SchemaId = property.TypeName, Filter = tagboxAttributes?.Filter, SchemaIndexingInfo = schemaIndexingAttribute?.SchemaIndexingInfo, ListItemCreateTemplate = listItemCreateTemplateAttribute?.ListItemCreateTemplate }; } else { field = new FieldSingleFieldset { Index = true, SimpleSearch = true, SchemaId = property.TypeName, SchemaIndexingInfo = schemaIndexingAttribute?.SchemaIndexingInfo }; } } } if (field == null) { throw new Exception($"Could not find type for {property.Name}"); } foreach (var attribute in property.PictureparkAttributes) { if (attribute is PictureparkSearchAttribute searchAttribute) { field.Index = searchAttribute.Index; field.SimpleSearch = searchAttribute.SimpleSearch; if (field.GetType().GetRuntimeProperty("Boost") != null) { field.GetType().GetRuntimeProperty("Boost").SetValue(field, searchAttribute.Boost); } } if (attribute is PictureparkRequiredAttribute) { field.Required = true; } if (attribute is PictureparkMaximumLengthAttribute maxLengthAttribute) { field.GetType().GetRuntimeProperty("MaximumLength").SetValue(field, maxLengthAttribute.Length); } if (attribute is PictureparkPatternAttribute patternAttribute) { field.GetType().GetRuntimeProperty("Pattern").SetValue(field, patternAttribute.Pattern); } if (attribute is PictureparkNameTranslationAttribute nameTranslationAttribute) { if (field.Names == null) { field.Names = new TranslatedStringDictionary(); } field.Names[nameTranslationAttribute.LanguageAbbreviation] = nameTranslationAttribute.Translation; } } var fieldName = property.Name; field.Id = fieldName.ToLowerCamelCase(); if (field.Names == null) { field.Names = new TranslatedStringDictionary { ["x-default"] = fieldName }; } var fieldAnalyzers = property.PictureparkAttributes .OfType <PictureparkAnalyzerAttribute>() .Select(a => a.CreateAnalyzer()) .ToList(); if (fieldAnalyzers.Any()) { field.GetType().GetRuntimeProperty("Analyzers").SetValue(field, fieldAnalyzers); } return(field); }
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 void CreateField(ClientContext ctx) { Web web = ctx.Site.RootWeb; // sharepoint client object model way //string fieldXml = @"<Field Type='DateTime' // DisplayName='Important Date2' // Required='TRUE' // EnforceUniqueValues='FALSE' // Indexed='FALSE' // Format='DateTime' // Group='Custom Columns' // ID='{C8DDEC78-F94E-4822-AB10-63FCDCA4AFEB}' // StaticName='Important_Date2' // Name='Important_Date2' > // <Default> // [today] // </Default> // </Field>"; //web.Fields.AddFieldAsXml(fieldXml, false, AddFieldOptions.DefaultValue); // ctx.ExecuteQuery(); /// PNP way //FieldCreationInformation fieldinfo = new FieldCreationInformation(FieldType.DateTime); //fieldinfo.Group = "Custom Columns"; //fieldinfo.Id = new Guid("{81682584-4E54-4D73-9DF9-E0FE3688833D}"); //fieldinfo.InternalName = "Important_Date3"; //fieldinfo.DisplayName = "important date 3"; //FieldDateTime datetimeField = web.CreateField<FieldDateTime>(fieldinfo); //datetimeField.DefaultValue = "[today]"; //datetimeField.DisplayFormat = DateTimeFieldFormatType.DateTime; //datetimeField.UpdateAndPushChanges(true); //ctx.ExecuteQuery(); FieldCreationInformation fieldinfo = new FieldCreationInformation(FieldType.DateTime); fieldinfo.Group = "Custom Columns"; fieldinfo.Id = new Guid("{81682584-4E54-4D73-9DF9-E0FE3688833D}"); fieldinfo.InternalName = "Important_Date3"; fieldinfo.DisplayName = "important date 3"; Field field = web.CreateField(fieldinfo); FieldDateTime datetimeField = ctx.CastTo <FieldDateTime>(field); datetimeField.DefaultValue = "[today]"; datetimeField.DisplayFormat = DateTimeFieldFormatType.DateTime; datetimeField.UpdateAndPushChanges(true); ctx.ExecuteQuery(); // DeleteFields(ctx); string pathToXML = AppDomain.CurrentDomain.BaseDirectory + "fields.xml"; ctx.Web.CreateFieldsFromXMLFile(pathToXML); }
public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties) { SPRemoteEventResult result = new SPRemoteEventResult(); //get the host web url Uri hostUrl = properties.AppEventProperties.HostWebFullUrl; //get the operation context so we can figure out the host URL for this service, from //which we can get the Authority for a client context System.ServiceModel.OperationContext oc = System.ServiceModel.OperationContext.Current; Uri localUrl = null; //UPDATE: THIS CODE WORKED FINE FOR WHEN YOU USE THE WEB APP CREATED BY VS.NET //FOR THE SHAREPOINT APP, BUT IT BREAKS WHEN YOU DEPLOY TO A REAL IIS SERVER //BECAUSE YOU END UP GETTING TWO BASEADDRESSES, BUT NOT WITH THE RIGHT SCHEME. //FOR EXAMPLE, THE FIRST ONE IS THE ADDRESS OF THIS HOST BUT WITH THE HTTP SCHEME. //THE SECOND ONE IS HTTPS, BUT THE HOST NAME IS THE FQDN OF THE SERVER. SINCE //SHAREPOINT DOESN'T RECOGNIZE THAT AS THE ENDPOINT IT TRUSTS FOR THIS CODE, IT BLOWS //UP WHEN RUNNING THE CODE BELOW AND THE WHOLE THING FAILS #region Code That Breaks In IIS ////now enumerate through the Host base addresses and look for the SSL connection //foreach (Uri u in oc.Host.BaseAddresses) //{ // if (u.Scheme.ToLower() == "https") // { // localUrl = u; // break; // } //} #endregion //assume first base address is ours, which it has been so far if (oc.Host.BaseAddresses.Count > 0) { localUrl = oc.Host.BaseAddresses[0]; } //make sure we found our local URL if (localUrl != null) { //using (ClientContext ctx = TokenHelper.CreateAppEventClientContext(properties, false)) using (ClientContext ctx = TokenHelper.GetClientContextWithContextToken(hostUrl.ToString(), properties.ContextToken, localUrl.Authority)) { if (ctx != null) { //try to retrieve the list first to see if it exists List l = ctx.Web.Lists.GetByTitle(LIST_NAME); ctx.Load(l); //have to put in a try block because of course it throw an exception if //list doesn't exist try { ctx.ExecuteQuery(); } catch (Exception noListEx) { //look to see if the exception is that the list doesn't exist if (noListEx.Message.ToLower().Contains("does not exist")) { //code here to create list Web web = ctx.Web; ListCreationInformation ci = new ListCreationInformation(); ci.Title = LIST_NAME; ci.TemplateType = (int)ListTemplateType.GenericList; ci.QuickLaunchOption = QuickLaunchOptions.Off; l = web.Lists.Add(ci); l.Description = "List for tracking events with the Event Planner Social App"; Field fldEventName = l.Fields.AddFieldAsXml("<Field DisplayName='EventName' Type='Text' />", true, AddFieldOptions.DefaultValue); Field fldSiteUrl = l.Fields.AddFieldAsXml("<Field DisplayName='SiteUrl' Type='Text' />", true, AddFieldOptions.DefaultValue); Field fldTwitterTags = l.Fields.AddFieldAsXml("<Field DisplayName='TwitterTags' Type='Text' />", true, AddFieldOptions.DefaultValue); Field fldEventDate = l.Fields.AddFieldAsXml("<Field DisplayName='EventDate' Type='DateTime' />", true, AddFieldOptions.DefaultValue); FieldDateTime dtEventDate = ctx.CastTo <FieldDateTime>(fldEventDate); dtEventDate.DisplayFormat = DateTimeFieldFormatType.DateOnly; dtEventDate.Update(); Field fldGraphID = l.Fields.AddFieldAsXml("<Field DisplayName='ObjectGraphID' Type='Text' />", true, AddFieldOptions.DefaultValue); FieldText txtGraphID = ctx.CastTo <FieldText>(fldGraphID); txtGraphID.Indexed = true; txtGraphID.Update(); l.Hidden = true; l.Update(); try { //this creates the list ctx.ExecuteQuery(); //all of the rest of this is to remove the list from the "Recent" list that appears //in sites by default, which is really a set of navigation links //get the site and root web, where the navigation lives Site s = ctx.Site; Web rw = s.RootWeb; //get the QuickLaunch navigation, which is where the Recent nav lives ctx.Load(rw, x => x.Navigation, x => x.Navigation.QuickLaunch); ctx.ExecuteQuery(); //now extract the Recent navigation node from the collection var vNode = from NavigationNode nn in rw.Navigation.QuickLaunch where nn.Title == "Recent" select nn; NavigationNode nNode = vNode.First <NavigationNode>(); //now we need to get the child nodes of Recent, that's where our list should be found ctx.Load(nNode.Children); ctx.ExecuteQuery(); var vcNode = from NavigationNode cn in nNode.Children where cn.Title == LIST_NAME select cn; //now that we have the node representing our list, delete it NavigationNode cNode = vcNode.First <NavigationNode>(); cNode.DeleteObject(); ctx.ExecuteQuery(); } catch (Exception newListFailEx) { Debug.WriteLine("Creation of new list failed: " + newListFailEx.Message); } } } //okay, so if we're here then the list should exist, and we should be good to go at this point } } } #region OOB Template Code //using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, false)) //{ // if (clientContext != null) // { // clientContext.Load(clientContext.Web); // clientContext.ExecuteQuery(); // } //} #endregion return(result); }
public FieldDateTimeInformation(FieldDateTime field) : base(field) { DateTimeCalendarType = (uint)field.DateTimeCalendarType; DisplayFormat = (uint)field.DisplayFormat; FriendlyDisplayFormat = (uint)field.FriendlyDisplayFormat; }
public static string GetCalendarType(this FieldDateTime field) { return(field.DateTimeCalendarType.ToString()); }
public static string GetDisplayFormat(this FieldDateTime field) { return(field.DisplayFormat.ToString()); }
public static void CreateBookCT(ClientContext ctx) { string bookCT = "0x01000E870749A9444905BB8A362E475B0798"; Web web = ctx.Site.RootWeb; //web.GetListByTitle("Books2").DeleteObject(); //ctx.ExecuteQuery(); //web.DeleteContentTypeById(bookCT); if (!web.ContentTypeExistsById(bookCT)) { web.CreateContentType("David Books", bookCT, "Davids ContentType"); } string bookTypeFieldId = "{DBB24705-0DEA-4C4F-8C2A-95CB6F0DE25E}"; if (!web.FieldExistsById(new Guid(bookTypeFieldId))) { FieldCreationInformation info = new FieldCreationInformation(FieldType.Choice); info.Id = bookTypeFieldId.ToGuid(); info.InternalName = "DAV_BookType"; info.DisplayName = "Book Type"; info.Group = "Tims Columns"; FieldChoice field = web.CreateField <FieldChoice>(info); field.Choices = new string[] { "Romance", "Drama", "Horror", "Thriller" }; field.Update(); ctx.ExecuteQuery(); } string authorFieldId = "{D6996667-0BEA-4C9F-9904-DEB21CC5AA84}"; if (!web.FieldExistsById(new Guid(authorFieldId))) { FieldCreationInformation info = new FieldCreationInformation(FieldType.Text); info.Id = authorFieldId.ToGuid(); info.InternalName = "DAV_Author"; info.DisplayName = "Author"; info.Group = "Tims Columns"; Field field = web.CreateField(info); } string releaseDateFieldId = "{84716863-06CA-4D31-BAA0-7D099FC501E7}"; if (!web.FieldExistsById(new Guid(releaseDateFieldId))) { FieldCreationInformation info = new FieldCreationInformation(FieldType.DateTime); info.Id = releaseDateFieldId.ToGuid(); info.InternalName = "DAV_Realesedate"; info.DisplayName = "ReleaseDate"; info.Group = "Tims Columns"; FieldDateTime field = web.CreateField <FieldDateTime>(info); field.DisplayFormat = DateTimeFieldFormatType.DateOnly; field.Update(); ctx.ExecuteQuery(); } string descriptionDateFieldId = "{4BD3F599-4D5C-412D-8431-6ECD36AEB015}"; // web.RemoveFieldById(descriptionDateFieldId); if (!web.FieldExistsById(new Guid(descriptionDateFieldId))) { FieldCreationInformation info = new FieldCreationInformation(FieldType.Note); info.Id = descriptionDateFieldId.ToGuid(); info.InternalName = "DAV_description"; info.DisplayName = "Description"; info.Group = "Tims Columns"; info.Required = true; FieldMultiLineText field = web.CreateField <FieldMultiLineText>(info); field.RichText = true; field.NumberOfLines = 10; field.AllowHyperlink = true; field.Update(); ctx.ExecuteQuery(); } web.AddFieldToContentTypeById(bookCT, bookTypeFieldId); web.AddFieldToContentTypeById(bookCT, authorFieldId); web.AddFieldToContentTypeById(bookCT, releaseDateFieldId); web.AddFieldToContentTypeById(bookCT, descriptionDateFieldId, true); if (!web.ListExists("Books2")) { List list = web.CreateList(ListTemplateType.GenericList, "Books2", false, urlPath: "lists/books2", enableContentTypes: true); list.AddContentTypeToListById(bookCT, true); View listView = list.DefaultView; listView.ViewFields.Add("DAV_BookType"); listView.ViewFields.Add("DAV_Author"); listView.ViewFields.Add("DAV_Realesedate"); listView.ViewFields.Add("DAV_description"); listView.Update(); ctx.ExecuteQueryRetry(); } List bookList = web.GetListByTitle("Books2"); ListItem item = bookList.AddItem(new ListItemCreationInformation()); item["Title"] = "MistBorn"; item["DAV_BookType"] = "Fantasy"; item["DAV_Author"] = "Brandon Sanderson"; item["DAV_Realesedate"] = DateTime.Parse("2001-02-12"); item["DAV_description"] = "This is a decription \n\n is this a new line?"; item.Update(); ctx.ExecuteQuery(); //ListItemCollection items = bookList.GetItems(CamlQuery.CreateAllItemsQuery()); //ctx.Load(items); //ctx.ExecuteQuery(); }
public static void CreateOrdersList() { Console.WriteLine("Creating orders list..."); if (CustomersListExists()) { ListCreationInformation listInformationOrders = new ListCreationInformation(); listInformationOrders.Title = "Orders"; listInformationOrders.Url = "Lists/Orders"; listInformationOrders.QuickLaunchOption = QuickLaunchOptions.On; listInformationOrders.TemplateType = (int)ListTemplateType.GenericList; listOrders = site.Lists.Add(listInformationOrders); listOrders.OnQuickLaunch = true; listOrders.EnableAttachments = false; listOrders.Update(); clientContext.ExecuteQuery(); clientContext.Load(listOrders.DefaultView.ViewFields); clientContext.ExecuteQuery(); listOrders.DefaultView.ViewFields.RemoveAll(); listOrders.DefaultView.ViewFields.Add("ID"); listOrders.DefaultView.ViewFields.Add("Title"); listOrders.DefaultView.Update(); clientContext.ExecuteQuery(); string fldCustomerLookupXml = @"<Field Name='Customer' DisplayName='Customer' Type='Lookup' ></Field>"; FieldLookup fldCustomerLookup = clientContext.CastTo <FieldLookup>(listOrders.Fields.AddFieldAsXml(fldCustomerLookupXml, true, AddFieldOptions.DefaultValue)); // add cusotmer lookup field fldCustomerLookup.LookupField = "Title"; fldCustomerLookup.LookupList = listCustomers.Id.ToString(); fldCustomerLookup.Indexed = true; fldCustomerLookup.RelationshipDeleteBehavior = RelationshipDeleteBehaviorType.Cascade; fldCustomerLookup.Update(); // add order date field string fldOrderDateXml = @"<Field Name='OrderDate' DisplayName='OrderDate' Type='DateTime' ></Field>"; FieldDateTime fldOrderDate = clientContext.CastTo <FieldDateTime>(listOrders.Fields.AddFieldAsXml(fldOrderDateXml, true, AddFieldOptions.DefaultValue)); fldOrderDate.DisplayFormat = DateTimeFieldFormatType.DateOnly; fldOrderDate.Update(); // add order date field string fldOrderAmountXml = @"<Field Name='OrderAmount' DisplayName='OrderAmount' Type='Currency' ></Field>"; FieldCurrency fldOrderAmount = clientContext.CastTo <FieldCurrency>(listOrders.Fields.AddFieldAsXml(fldOrderAmountXml, true, AddFieldOptions.DefaultValue)); fldOrderAmount.Update(); clientContext.ExecuteQuery(); clientContext.Load(listOrders); clientContext.ExecuteQuery(); } else { Console.WriteLine("Cannot create Orders list because Customer list does not exist."); } }