/// <summary>Checks to see if the role exists.</summary> public bool IsRoleExist(string role) { try { if (m_calendarsListURL.Length > 0) { string listName; string url = ParseSiteUrl(m_calendarsListURL, out listName); using (SPSite site = new SPSite(url)) { using (SPWeb web = site.OpenWeb()) { SPList list = web.Lists[listName.Replace("%20", " ")]; SPFieldMultiChoice roleField = (SPFieldMultiChoice)list.Fields["Role"]; int index = roleField.Choices.IndexOf(role); return(index != -1); } } } else { return(false); } } catch (Exception) { return(false); } }
public override void AddFieldTo(SPFieldCollection fieldCollection) { AddFieldTo(fieldCollection, f => { SPFieldMultiChoice field = (SPFieldMultiChoice)f; field.Choices.Clear(); field.Choices.AddRange(Choices); }); }
public static void LoadDataChoiceFieldCheckboxes(this CheckBoxList checkBoxList, string fieldName, SPListItem spListItem, TextBox otherValueTextBoxControl, string choiceValueSpliter, string otherValue = "Khác/Others") { checkBoxList.Items.Clear(); otherValueTextBoxControl.Text = string.Empty; SPList spList = spListItem.ParentList; SPFieldMultiChoice fieldMultiChoie = spList.Fields.Cast <SPField>().ToList <SPField>().Where(f => f.StaticName.Equals(fieldName)).FirstOrDefault() as SPFieldMultiChoice; if (fieldMultiChoie != null) { var choices = fieldMultiChoie.Choices; foreach (var choice in choices) { ListItem item = new ListItem() { Text = choice, Value = choice }; checkBoxList.Items.Add(item); } // Check to select item of checkbox list. string[] fieldValueArray = null; if (spListItem[fieldName] != null) { fieldValueArray = spListItem[fieldName].ToString().Split(new string[] { choiceValueSpliter }, StringSplitOptions.RemoveEmptyEntries); } if (fieldValueArray != null && fieldValueArray.Length > 0) { foreach (var fieldValue in fieldValueArray) { ListItem item = checkBoxList.Items.Cast <ListItem>().Where(listItem => (string.Compare(listItem.Value, fieldValue, true) == 0)).FirstOrDefault(); if (item != null) { item.Selected = true; } else { otherValueTextBoxControl.Text = fieldValue; ListItem otherListItem = checkBoxList.Items.Cast <ListItem>().Where(listItem => (string.Compare(listItem.Value, otherValue, true) == 0)).FirstOrDefault(); if (otherListItem != null) { otherListItem.Selected = true; } } } } } }
internal static bool CreateOrUpdate_CCSAdvancedAlertsForTemplateList(SPWeb rootWeb) { try { rootWeb.AllowUnsafeUpdates = true; //Get dependent lists SPList templatelist = rootWeb.Lists.TryGetList("CCSAdvancedAlertsMailTemplates"); SPList alertList = rootWeb.Lists.TryGetList("CCSAdvancedAlertsList"); SPList templateForAlertList = null; //Creating delayed alert list Guid guid = rootWeb.Lists.Add("CCSAdvancedTemplateForAlert", "CCS Advanced Template For Alert", SPListTemplateType.GenericList); templateForAlertList = rootWeb.Lists[guid]; //set the list settings templateForAlertList.Hidden = true; templateForAlertList.NoCrawl = true; templateForAlertList.OnQuickLaunch = false; //Add fields templateForAlertList.Fields.AddLookup("Template ", templatelist.ID, false); templateForAlertList.Fields.AddLookup("Alert ", alertList.ID, false); string fieldName = templateForAlertList.Fields.Add("EventType ", SPFieldType.MultiChoice, false); SPFieldMultiChoice multiChoices = (SPFieldMultiChoice)templateForAlertList.Fields[fieldName]; multiChoices.Choices.Add(AlertEventType.ItemAdded.ToString()); multiChoices.Choices.Add(AlertEventType.ItemAdded.ToString()); multiChoices.Choices.Add(AlertEventType.ItemAdded.ToString()); multiChoices.Choices.Add(AlertEventType.ItemAdded.ToString()); multiChoices.Update(); templateForAlertList.Fields.Add("InsertUpdatedFields ", SPFieldType.Boolean, false); templateForAlertList.Fields.Add("HighLightUpdatedFields ", SPFieldType.Boolean, false); templateForAlertList.Fields.Add("InsertAttachments ", SPFieldType.Boolean, false); templateForAlertList.Update(); rootWeb.AllowUnsafeUpdates = false; } catch { return(false); } return(true); }
internal static bool CreateOrUpdate_CCSAdvancedDelayedAlertsList(SPWeb rootWeb) { try { SPList alertList = rootWeb.Lists.TryGetList("CCSAdvancedAlertsList"); SPList delayedAlertList = null; rootWeb.AllowUnsafeUpdates = true; //Creating delayed alert list Guid guid = rootWeb.Lists.Add("CCSAdvancedDelayedAlerts", "CCS Advanced Delayed Alerts", SPListTemplateType.GenericList); delayedAlertList = rootWeb.Lists[guid]; //set the list settings delayedAlertList.Hidden = true; delayedAlertList.NoCrawl = true; delayedAlertList.OnQuickLaunch = false; //Add fields delayedAlertList.Fields.Add("Subject ", SPFieldType.Text, false); delayedAlertList.Fields.Add("Body ", SPFieldType.Text, false); delayedAlertList.Fields.AddLookup("Alert ", alertList.ID, false); delayedAlertList.Fields.Add("ItemID ", SPFieldType.Text, false); string fieldName = delayedAlertList.Fields.Add("EventType ", SPFieldType.MultiChoice, false); SPFieldMultiChoice multiChoices = (SPFieldMultiChoice)delayedAlertList.Fields[fieldName]; multiChoices.Choices.Add(AlertEventType.ItemAdded.ToString()); multiChoices.Choices.Add(AlertEventType.ItemAdded.ToString()); multiChoices.Choices.Add(AlertEventType.ItemAdded.ToString()); multiChoices.Choices.Add(AlertEventType.ItemAdded.ToString()); multiChoices.Update(); delayedAlertList.Update(); rootWeb.AllowUnsafeUpdates = false; } catch { return(false); } return(true); }
public static void LoadDataChoiceFieldDropDown(this DropDownList dropDownList, string fieldName, SPListItem spListItem, string blankValueItem = "", string blankTextItem = "") { dropDownList.Items.Clear(); SPList spList = spListItem.ParentList; SPFieldMultiChoice fieldMultiChoie = spList.Fields.Cast <SPField>().ToList <SPField>().Where(f => f.StaticName.Equals(fieldName)).FirstOrDefault() as SPFieldMultiChoice; if (fieldMultiChoie != null) { var fieldValue = string.Empty; if (spListItem[fieldName] != null) { fieldValue = spListItem[fieldName].ToString(); } var choices = fieldMultiChoie.Choices; foreach (var choice in choices) { ListItem item = new ListItem() { Text = choice, Value = choice }; if (string.Compare(fieldValue, choice, true) == 0) { item.Selected = true; } dropDownList.Items.Add(item); } // Not Required if (!fieldMultiChoie.Required) { ListItem emptyItem = new ListItem() { Text = blankTextItem, Value = blankValueItem }; dropDownList.Items.Insert(0, emptyItem); } } }
public static SPFieldMultiChoice EnsureChoiceField(this SPList list, string fieldName, List <string> chioces, bool isMultiSelect, bool fillInChoice = false) { SPFieldMultiChoice field = null; try { SPSecurity.RunWithElevatedPrivileges(delegate() { if (!list.Fields.ContainsField(fieldName)) { if (isMultiSelect) { list.Fields.Add(fieldName, SPFieldType.MultiChoice, false); } else { list.Fields.Add(fieldName, SPFieldType.Choice, false); } list.Update(); } field = (SPFieldMultiChoice)list.TryGetField(fieldName); field.FillInChoice = fillInChoice; field.Choices.Clear(); foreach (string str in chioces) { field.Choices.Add(str); } field.Update(); list.Update(); }); return(field); } catch (Exception ex) { Log.Error(ex); return(field); } }
private static List <SPFieldGeneral> getFieldsFromList(SPList list, string contentTypeId) { SPContentType type = list.ContentTypes[contentTypeId]; List <SPFieldGeneral> listFields = new List <SPFieldGeneral>(); SPFieldCollection fields = (contentTypeId != "") ? list.ContentTypes[new SPContentTypeId(contentTypeId)].Fields : list.ContentTypes[0].Fields; foreach (SPField field in fields) { if ((field.Hidden || (field.FromBaseType && (field.InternalName != "Title"))) || ((field.InternalName == "Status") || (field.InternalName == "CurrentUser"))) { continue; } SPFieldGeneral general = new SPFieldGeneral(); string str = field.Type.ToString(); general.Guid = field.Id; general.InternalName = field.InternalName; XmlDocument document = new XmlDocument(); document.LoadXml(field.SchemaXml); XmlElement documentElement = document.DocumentElement; if (documentElement.HasAttribute("DisplayName")) { general.Title = documentElement.GetAttribute("DisplayName"); } else { general.Title = field.Title; } general.Title = field.GetProperty("DisplayName"); general.Disable = field.GetProperty("Disable"); general.NotShow = field.GetProperty("NotShow"); string[] notShowArr = general.NotShow != null?general.NotShow.Split(',') : new string[] { }; general.DefaultValue = field.DefaultValue; general.IsRequire = field.Required; general.Type = field.TypeAsString; general.Description = field.Description; switch (field.TypeAsString) { case "Text": general.MaxLength = ((SPFieldText)field).MaxLength; break; case "Number": general.MaxValue = ((SPFieldNumber)field).MaximumValue; general.MinValue = ((SPFieldNumber)field).MinimumValue; general.ShowAsPercentage = ((SPFieldNumber)field).ShowAsPercentage; break; case "Lookup": general.LookupList = ((SPFieldLookup)field).LookupList.Replace("{", "").Replace("}", ""); general.LookupTitleField = "Title"; general.LookupValueField = "ID"; general.AllowMultipleValue = ((SPFieldLookup)field).AllowMultipleValues; break; case "LookupMulti": general.LookupList = ((SPFieldLookup)field).LookupList.Replace("{", "").Replace("}", ""); general.LookupTitleField = "Title"; general.LookupValueField = "ID"; general.AllowMultipleValue = ((SPFieldLookup)field).AllowMultipleValues; break; case "RelatedCustomLookupQuery": general.LookupList = field.GetCustomProperty("ListNameLookup").ToString().Replace("{", "").Replace("}", ""); general.LookupTitleField = field.GetCustomProperty("FieldTitleLookup").ToString(); general.LookupValueField = field.GetCustomProperty("FieldValueLookup").ToString(); general.AllowMultipleValue = ((SPFieldLookup)field).AllowMultipleValues; general.RelatedFields = field.GetCustomProperty("RelatedFields").ToString().Split(new char[] { '|' }); general.Query = field.GetCustomProperty("QueryLookup").ToString(); if ((field.GetCustomProperty("IsFile") != null) ? bool.Parse(field.GetCustomProperty("IsFile").ToString()) : false) { general.Type = "File"; general.TypeFile = field.GetCustomProperty("TypeFile").ToString(); general.VolumeFile = field.GetCustomProperty("VolumeFile").ToString(); } break; case "MasterDetail": general.LookupList = field.GetCustomProperty("ListNameLookup").ToString(); general.RelatedFields = field.GetCustomProperty("RelatedFields").ToString().Split(new char[] { '|' }); general.MasterLookupName = field.GetCustomProperty("MasterFieldNameLookup").ToString(); break; case "CustomComputedField": general.LookupList = field.GetCustomProperty("ListNameQuery").ToString(); general.LookupTitleField = field.GetCustomProperty("FieldNameQuery").ToString(); general.Query = field.GetCustomProperty("TextQuery").ToString(); general.AggregationFunction = field.GetCustomProperty("AggregatorFunction").ToString(); break; case "Choice": { SPFieldChoice choice = (SPFieldChoice)field; general.options = new List <string>(); foreach (string str2 in choice.Choices) { general.options.Add(str2); } general.DefaultValue = ((SPFieldChoice)field).DefaultValue; general.AllowMultipleValue = ((SPFieldChoice)field).ListItemMenu; break; } case "MultiChoice": { SPFieldMultiChoice choice2 = (SPFieldMultiChoice)field; general.options = new List <string>(); foreach (string str2 in choice2.Choices) { general.options.Add(str2); } general.AllowMultipleValue = ((SPFieldMultiChoice)field).ListItemMenu; break; } } if (!notShowArr.Contains("New")) { listFields.Add(general); } } SPField fieldByInternalName = list.Fields.GetFieldByInternalName("ID"); SPFieldGeneral item = new SPFieldGeneral { Guid = fieldByInternalName.Id, InternalName = fieldByInternalName.InternalName, Title = fieldByInternalName.Title, DefaultValue = fieldByInternalName.DefaultValue, IsRequire = fieldByInternalName.Required, Type = fieldByInternalName.TypeAsString, Description = fieldByInternalName.Description }; listFields.Add(item); return(listFields); }
internal static bool CreateOrUpdate_CCSAdvancedAlertsList(SPWeb rootWebSite) { try { SPList alertLst = null; if (alertLst == null) { rootWebSite.AllowUnsafeUpdates = true; Guid guid = rootWebSite.Lists.Add("CCSAdvancedAlertsList", "CCS Advanced Alerts", SPListTemplateType.GenericList); alertLst = rootWebSite.Lists[guid]; //List setting alertLst.Hidden = true; alertLst.OnQuickLaunch = false; alertLst.NoCrawl = true; //Adding fields alertLst.Fields.Add("WebID", SPFieldType.Text, false); alertLst.Fields.Add("ListID", SPFieldType.Text, false); alertLst.Fields.Add("ItemID", SPFieldType.Text, false); alertLst.Fields.Add("Owner", SPFieldType.User, true); //alertLst.Fields.Add("Contents", 3, true); string str = alertLst.Fields.Add("ChangeTypes", SPFieldType.MultiChoice, true); SPFieldMultiChoice choice = (SPFieldMultiChoice)alertLst.Fields[str]; choice.Choices.Add(AlertEventType.ItemAdded.ToString()); choice.Choices.Add(AlertEventType.ItemUpdated.ToString()); choice.Choices.Add(AlertEventType.ItemDeleted.ToString()); choice.Choices.Add(AlertEventType.DateColumn.ToString()); choice.Update(); string str2 = alertLst.Fields.Add("Timing", SPFieldType.Choice, true); SPFieldChoice choice2 = (SPFieldChoice)alertLst.Fields[str2]; choice2.Choices.Add(SendType.ImmediateAlways.ToString()); choice2.Choices.Add(SendType.ImmediateBusinessDays.ToString()); choice2.Choices.Add(SendType.Daily.ToString()); choice2.Choices.Add(SendType.Weekly.ToString()); choice2.Update(); //string str3 = alertLst.get_Fields().Add("SendDay", 6, true); //SPFieldChoice choice3 = alertLst.get_Fields().get_Item(str3); //for (int i = 1; i < 8; i++) //{ // choice3.get_Choices().Add(i.ToString()); //} //choice3.Update(); //string str4 = alertLst.get_Fields().Add("SendHour", 6, true); //SPFieldChoice choice4 = alertLst.get_Fields().get_Item(str4); //for (int j = 0; j < 0x17; j++) //{ // choice4.get_Choices().Add(j.ToString()); //} //choice4.Update(); alertLst.Update(); rootWebSite.AllowUnsafeUpdates = false; } } catch { return(false); } return(true); }
public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPWeb web = (SPWeb)properties.Feature.Parent; SPSite site = web.Site; web.AllowUnsafeUpdates = true; Lists listRoot = GetListsInfo(properties); foreach (List listInfo in listRoot.Items) { SPList tempList = null; if (listInfo.name != null) { listName = listInfo.name.Trim(); } else { throw new Exception(Constants.LIST_NAME_ERROR); } descName = listInfo.description; if (CheckList(web, listName)) { tempList = web.Lists[web.Lists.Add(listName, descName, SPListTemplateType.GenericList)]; } else { tempList = web.Lists[listName]; } if (tempList != null) { foreach (Field fields in listInfo.Fields) { SPFieldType fldType = SPFieldType.Text; ClearFlags(); if (fields.name != null) { fieldname = fields.name.Trim(); } else { throw new Exception(Constants.FIELD_NAME_ERROR + listName); } if (fields.datatype != null) { fieldtype = fields.datatype.Trim(); } if (fields.required != null) { required = fields.required.Trim(); } if (fields.defaultvalue != null) { defaultValue = fields.defaultvalue.Trim(); } if (fields.textformat != null) { textFormat = fields.textformat.Trim(); } if (fields.displaychoicesusing != null) { displayChoicesUsing = fields.displaychoicesusing.Trim(); } if (fields.lookuplist != null) { lookupList = fields.lookuplist.Trim(); } if (fields.lookupfield != null) { lookupfield = fields.lookupfield.Trim(); } switch (fieldtype.ToLower()) { case Constants.SINGLE_LINE_TEXT_TYPE: fldType = SPFieldType.Text; break; case Constants.MULTIPLE_LINE_TEXT_TYPE: fldType = SPFieldType.Note; break; case Constants.DATETIME_TYPE: fldType = SPFieldType.DateTime; break; case Constants.NUMBER_TYPE: fldType = SPFieldType.Number; break; case Constants.CURRENCY_TYPE: fldType = SPFieldType.Currency; break; case Constants.YESNO_TYPE: fldType = SPFieldType.Boolean; break; case Constants.PERSON_GROUP_TYPE: fldType = SPFieldType.User; break; case Constants.HYPERLINK_PICTURE_TYPE: fldType = SPFieldType.URL; break; case Constants.CHOICE_TYPE: if (displayChoicesUsing.ToLower().Trim().Equals(Constants.MULTICHECKBOX)) { fldType = SPFieldType.MultiChoice; } else { fldType = SPFieldType.Choice; } break; case Constants.LOOKUP_TYPE: fldType = SPFieldType.Lookup; break; } SPField field = tempList.Fields.CreateNewField(fldType.ToString(), fieldname); field.DefaultValue = defaultValue; field.Description = fielddesc; field.Required = (required.ToLower().Trim().Equals(Constants.YES) ? true : false); if (!tempList.Fields.ContainsField(fieldname)) { tempList.Fields.Add(field); } if ((tempList.Fields[fieldname] as SPFieldText) != null) { int maxLength; int.TryParse(maxCount, out maxLength); var fldText = tempList.Fields[fieldname] as SPFieldText; if (fldText != null && maxLength > 0) { fldText.MaxLength = maxLength; fldText.Update(); tempList.Update(); } continue; } if ((tempList.Fields[fieldname] as SPFieldMultiLineText) != null) { int noOfLines; int.TryParse(NoOfLines, out noOfLines); SPFieldMultiLineText fldMultiText = tempList.Fields[fieldname] as SPFieldMultiLineText; fldMultiText.NumberOfLines = (noOfLines > 0) ? noOfLines : fldMultiText.NumberOfLines; fldMultiText.RichText = (textFormat.ToLower().Trim().Equals(Constants.RICHTEXT)) ? true : false; fldMultiText.Update(); tempList.Update(); continue; } if ((tempList.Fields[fieldname] as SPFieldBoolean) != null) { SPFieldBoolean fldBoolean = (tempList.Fields[fieldname]) as SPFieldBoolean; // useful in future tempList.Update(); continue; } if ((tempList.Fields[fieldname] as SPFieldUser) != null) { SPFieldUser fldUser = tempList.Fields[fieldname] as SPFieldUser; // useful in future tempList.Update(); continue; } if (tempList.Fields[fieldname] as SPFieldMultiChoice != null) { SPFieldMultiChoice fldMultiChoice = tempList.Fields[fieldname] as SPFieldMultiChoice; foreach (Choice choiceNodes in fields.Choices) { fldMultiChoice.Choices.Add(choiceNodes.Value); } fldMultiChoice.Update(); tempList.Update(); continue; } if ((tempList.Fields[fieldname] as SPFieldChoice) != null) { SPFieldChoice fldChoice = tempList.Fields[fieldname] as SPFieldChoice; if (displayChoicesUsing.ToLower().Trim().Equals(Constants.DROPDOWNMENU)) { fldChoice.EditFormat = SPChoiceFormatType.Dropdown; } if (displayChoicesUsing.ToLower().Trim().Equals(Constants.RADIOBUTTONS)) { fldChoice.EditFormat = SPChoiceFormatType.RadioButtons; } // Add the choices foreach (Choice choiceNodes in fields.Choices) { fldChoice.Choices.Add(choiceNodes.Value); } fldChoice.Update(); tempList.Update(); continue; } if ((tempList.Fields[fieldname] as SPFieldLookup) != null) { SPFieldLookup fldLookup = tempList.Fields[fieldname] as SPFieldLookup; SPList parentList = web.Lists[lookupList]; fldLookup.LookupList = parentList.ID.ToString(); fldLookup.LookupField = parentList.Fields[lookupfield].InternalName; fldLookup.Update(); tempList.Update(); continue; } } } } web.Update(); web.AllowUnsafeUpdates = true; }
private static string GetFieldType(SPField oField, out string senum, out string senumkeys, out string sFormat, out string sRange, SPWeb oWeb) { var currencyFormatDictionary = new Dictionary <int, string> { { 0, "$n" }, { 1, "n$" }, { 2, "$ n" }, { 3, "n $" } }; senum = ""; senumkeys = ""; sFormat = ""; sRange = ""; switch (oField.Type) { case SPFieldType.Boolean: return("Bool"); case SPFieldType.DateTime: SPFieldDateTime oDTField = (SPFieldDateTime)oField; string dateFormat = GetExampleDateFormat(oWeb, "yyyy", "M", "d"); sFormat = oDTField.GetProperty("Format").Equals("DateOnly") ? dateFormat : string.Format("{0} h:mm tt", dateFormat); return("Date"); case SPFieldType.Currency: var currenvyCultureInfo = new CultureInfo(((SPFieldCurrency)oField).CurrencyLocaleId); NumberFormatInfo numberFormatInfo = currenvyCultureInfo.NumberFormat; sFormat = currencyFormatDictionary[numberFormatInfo.CurrencyPositivePattern] .Replace("$", numberFormatInfo.CurrencySymbol) .Replace("n", string.Format(",0.{0}", new string('0', numberFormatInfo.CurrencyDecimalDigits))); return("Float"); case SPFieldType.Note: SPFieldMultiLineText field = (SPFieldMultiLineText)oField; if (field.RichText) { return("Html"); } else { return("Lines"); } case SPFieldType.Number: string percentageSign = string.Empty; if (((SPFieldNumber)oField).ShowAsPercentage) { //sFormat = "0\\%;0\\%;0\\%"; return("Float"); } switch (((SPFieldNumber)oField).DisplayFormat) { case SPNumberFormatTypes.Automatic: sFormat = ",#0.##########" + percentageSign; break; case SPNumberFormatTypes.NoDecimal: sFormat = ",#0" + percentageSign; break; case SPNumberFormatTypes.OneDecimal: sFormat = ",#0.0" + percentageSign; break; case SPNumberFormatTypes.TwoDecimals: sFormat = ",#0.00" + percentageSign; break; case SPNumberFormatTypes.ThreeDecimals: sFormat = ",#0.000" + percentageSign; break; case SPNumberFormatTypes.FourDecimals: sFormat = ",#0.0000" + percentageSign; break; case SPNumberFormatTypes.FiveDecimals: sFormat = ",#0.00000" + percentageSign; break; } return("Float"); case SPFieldType.Choice: SPFieldChoice oCField = (SPFieldChoice)oField; foreach (string sChoice in oCField.Choices) { senum += ";" + sChoice; } return("Enum"); case SPFieldType.Lookup: SPFieldLookup oLField = (SPFieldLookup)oField; if (oLField.AllowMultipleValues) { sRange = "1"; } SPList oLookupList = oWeb.Lists[new Guid(oLField.LookupList)]; foreach (SPListItem li in oLookupList.Items) { senum += ";" + li.Title.Replace(";", ""); senumkeys += ";" + li.ID; } return("Enum"); case SPFieldType.MultiChoice: SPFieldMultiChoice oMCField = (SPFieldMultiChoice)oField; foreach (string sChoice in oMCField.Choices) { senum += ";" + sChoice; } sRange = "1"; return("Enum"); case SPFieldType.User: DataTable dtResources = EPMLiveCore.API.APITeam.GetResourcePool("<Pool><Columns>SimpleColumns</Columns></Pool>", oWeb); foreach (DataRow dr in dtResources.Rows) { senum += ";" + dr["Title"].ToString(); senumkeys += ";" + dr["SPID"].ToString(); } SPFieldUser oUField = (SPFieldUser)oField; if (oUField.AllowMultipleValues) { sRange = "1"; } return("Enum"); default: return("Text"); } }
public void MultiChoice() { // // Create list. // SPList lst = Test.CreateList <ChoiceTest2>(site.RootWeb); // // Add fields. // lst.Fields.Add("Options", SPFieldType.MultiChoice, true); lst.Update(); SPFieldMultiChoice fld = new SPFieldMultiChoice(lst.Fields, "Options"); fld.Choices.Add("A"); fld.Choices.Add("B"); fld.Choices.Add("C & D"); fld.Update(); lst.Update(); // // Add items. // SPListItem item = lst.Items.Add(); item["Title"] = "1"; item["Options"] = "A"; item.Update(); item = lst.Items.Add(); item["Title"] = "2"; item["Options"] = "C & D"; item.Update(); item = lst.Items.Add(); item["Title"] = "3"; item["Options"] = "A;#C & D"; item.Update(); item = lst.Items.Add(); item["Title"] = "4"; item["Options"] = "B"; item.Update(); // // List source. // SharePointDataSource <ChoiceTest2> src = new SharePointDataSource <ChoiceTest2>(site); src.CheckListVersion = false; // // Queries. // var res1 = (from c in src where c.Options == Options2.A select c).AsEnumerable(); Assert.IsTrue(res1.Count() == 2 && res1.First().Title == "1" && res1.Last().Title == "3", "Test for MultiChoice fields failed (1)."); var res2 = (from c in src where c.Options == Options2.CD select c).AsEnumerable(); Assert.IsTrue(res2.Count() == 2 && res2.First().Title == "2" && res2.Last().Title == "3", "Test for MultiChoice fields failed (2)."); var res3 = (from c in src where c.Options == (Options2.A | Options2.B) select c).AsEnumerable(); Assert.IsTrue(res3.Count() == 0, "Test for MultiChoice fields failed (3)."); var res4 = (from c in src where c.Options == Options2.A || c.Options == Options2.B select c).AsEnumerable(); Assert.IsTrue(res4.Count() == 3, "Test for MultiChoice fields failed (4)."); var res5 = (from c in src where c.Options != Options2.A select c).AsEnumerable(); Assert.IsTrue(res5.Count() == 2, "Test for MultiChoice fields failed (5)."); }
public QueryControlMultiChioce(SPField f) { _Field = (SPFieldMultiChoice)f; }
protected override void outputXml() { tb.AddTimer(); XmlDocument doc = new XmlDocument(); doc.LoadXml(Properties.Resources.txtGanttLayout.Replace("#gridid#", base.gridname)); XmlNode ndHeader = doc.FirstChild.SelectSingleNode("//Header"); XmlNode ndCols = doc.FirstChild.SelectSingleNode("//LeftCols"); //XmlNode ndLeftCols = doc.FirstChild.SelectSingleNode("//LeftCols"); if (showCheckboxes) { doc.FirstChild.SelectSingleNode("//Panel").Attributes["Visible"].Value = "1"; } ArrayList arrFields = new ArrayList(); string sTitleField = "Title"; foreach (string field in aViewFields) { try { SPField oField = getRealField(list.Fields.GetFieldByInternalName(field)); if (oField.InternalName == "Title") { sTitleField = field; } arrFields.Add(oField.InternalName); XmlNode ndNew = doc.CreateNode(XmlNodeType.Element, "C", doc.NamespaceURI); XmlAttribute attr = doc.CreateAttribute("Name"); attr.Value = oField.InternalName; if (attr.Value == "State") { attr.Value = "FState"; } ndNew.Attributes.Append(attr); attr = doc.CreateAttribute("CaseSensitive"); attr.Value = "0"; ndNew.Attributes.Append(attr); XmlDocument oDoc = new XmlDocument(); oDoc.LoadXml(oField.SchemaXml); string sFormat = getFormat(oField, oDoc, SPContext.Current.Web); string sType = "Html"; string sTitle = oField.Title; string sTitleAlign = "Left"; if (sFormat != "") { attr = doc.CreateAttribute("Format"); attr.Value = sFormat; ndNew.Attributes.Append(attr); if (oField.Type == SPFieldType.Currency) { SPFieldCurrency c = (SPFieldCurrency)oField; System.Globalization.NumberFormatInfo nInfo = System.Globalization.CultureInfo.GetCultureInfo(c.CurrencyLocaleId).NumberFormat; if (sFormat.Contains(nInfo.CurrencySymbol)) { attr = doc.CreateAttribute("EditFormat"); attr.Value = sFormat.Replace(nInfo.CurrencySymbol, string.Empty); ndNew.Attributes.Append(attr); } } else { attr = doc.CreateAttribute("EditFormat"); attr.Value = sFormat; ndNew.Attributes.Append(attr); } } if (oField.InternalName == "Edit") { attr = doc.CreateAttribute("Width"); attr.Value = "50"; ndNew.Attributes.Append(attr); } else if (oField.InternalName == "Title") { attr = doc.CreateAttribute("MinWidth"); attr.Value = "300"; ndNew.Attributes.Append(attr); attr = doc.CreateAttribute("Button"); attr.Value = "Html"; ndNew.Attributes.Append(attr); attr = doc.CreateAttribute("RelWidth"); attr.Value = "1"; ndNew.Attributes.Append(attr); } else if (oField.InternalName == "WorkspaceUrl") { attr = doc.CreateAttribute("Width"); attr.Value = "60"; ndNew.Attributes.Append(attr); attr = doc.CreateAttribute("Align"); attr.Value = "Center"; sTitleAlign = "Center"; ndNew.Attributes.Append(attr); attr = doc.CreateAttribute("WorkspaceUrl"); attr.Value = "h"; ndHeader.Attributes.Append(attr); sTitle = ""; } else { string sWidth = "150"; switch (oField.Type) { case SPFieldType.Text: sWidth = "150"; break; case SPFieldType.Number: attr = doc.CreateAttribute("Align"); attr.Value = "Right"; sTitleAlign = "Right"; ndNew.Attributes.Append(attr); sType = "Float"; break; case SPFieldType.Currency: attr = doc.CreateAttribute("Align"); attr.Value = "Right"; sTitleAlign = "Right"; ndNew.Attributes.Append(attr); sType = "Float"; break; case SPFieldType.DateTime: attr = doc.CreateAttribute("Align"); attr.Value = "Left"; ndNew.Attributes.Append(attr); sType = "Date"; break; case SPFieldType.Boolean: sType = "Bool"; break; case SPFieldType.Calculated: SPFieldCalculated oFC = (SPFieldCalculated)oField; if (oFC.OutputType == SPFieldType.Number || oFC.OutputType == SPFieldType.Currency || oFC.OutputType == SPFieldType.DateTime) { attr = doc.CreateAttribute("Align"); attr.Value = "Right"; sTitleAlign = "Right"; ndNew.Attributes.Append(attr); if (oFC.OutputType == SPFieldType.DateTime) { sType = "Date"; } else { sType = "Float"; } } else if (oFC.Description == "Indicator") { attr = doc.CreateAttribute("Align"); attr.Value = "Center"; sTitleAlign = "Center"; ndNew.Attributes.Append(attr); sWidth = "80"; } break; case SPFieldType.Choice: sType = "Enum"; { //Reference: http://longboo.com/demo/ejs-treegrid/Doc/TypeEnum.htm string senum = ""; string senumrange = ""; SPFieldChoice oCField = (SPFieldChoice)oField; //Used to prepare dropdown with field choice options foreach (string sChoice in oCField.Choices) { senum += ";" + sChoice.Replace(";", ""); } //Used to prepare count for an item //for (int i = 0; i < oCField.Choices.Count; i++) // senumrange += ";" + i.ToString(); senumrange = senum; attr = doc.CreateAttribute("Enum"); attr.Value = senum; ndNew.Attributes.Append(attr); attr = doc.CreateAttribute("EnumKeys"); attr.Value = senumrange; ndNew.Attributes.Append(attr); } sWidth = "150"; break; case SPFieldType.Lookup: sWidth = "150"; sType = "Enum"; attr = doc.CreateAttribute("Enum"); attr.Value = ""; ndNew.Attributes.Append(attr); attr = doc.CreateAttribute("EnumKeys"); attr.Value = ""; ndNew.Attributes.Append(attr); if (oField.TypeAsString.Equals("LookupMulti", StringComparison.InvariantCultureIgnoreCase)) { attr = doc.CreateAttribute("Range"); attr.Value = "1"; ndNew.Attributes.Append(attr); } hshLookupEnums.Add(oField.InternalName, new ArrayList()); hshLookupEnumKeys.Add(oField.InternalName, new ArrayList()); break; case SPFieldType.MultiChoice: { string senum = ""; SPFieldMultiChoice oCField = (SPFieldMultiChoice)oField; foreach (string sChoice in oCField.Choices) { senum += ";" + sChoice.Replace(";", ""); } attr = doc.CreateAttribute("Enum"); attr.Value = senum; ndNew.Attributes.Append(attr); attr = doc.CreateAttribute("Range"); attr.Value = "1"; ndNew.Attributes.Append(attr); } sType = "Enum"; sWidth = "150"; break; case SPFieldType.Note: sWidth = "200"; break; case SPFieldType.URL: sWidth = "150"; break; case SPFieldType.User: sWidth = "150"; attr = doc.CreateAttribute("CaseSensitive"); attr.Value = "0"; ndNew.Attributes.Append(attr); break; default: switch (oField.TypeAsString) { case "TotalRollup": attr = doc.CreateAttribute("Align"); attr.Value = "Right"; sTitleAlign = "Right"; ndNew.Attributes.Append(attr); break; } break; } attr = doc.CreateAttribute("MinWidth"); attr.Value = sWidth; ndNew.Attributes.Append(attr); } attr = doc.CreateAttribute("Wrap"); attr.Value = "0"; ndNew.Attributes.Append(attr); attr = doc.CreateAttribute("Type"); attr.Value = sType; ndNew.Attributes.Append(attr); ndCols.AppendChild(ndNew); if (oField.InternalName == "Title") { ndCols = doc.FirstChild.SelectSingleNode("//Cols"); } string iFieldName = oField.InternalName; if (iFieldName == "State") { iFieldName = "FState"; } attr = doc.CreateAttribute(iFieldName); attr.Value = sTitle; ndHeader.Attributes.Append(attr); attr = doc.CreateAttribute(oField.InternalName + "Align"); attr.Value = sTitleAlign; ndHeader.Attributes.Append(attr); if (arrHidden.Contains(oField.InternalName)) { attr = doc.CreateAttribute("Visible"); attr.Value = "0"; ndNew.Attributes.Append(attr); } } catch { } } XmlNode ndGantt = doc.FirstChild.SelectSingleNode("//RightCols/C[@Name='G']"); ndGantt.Attributes["GanttStart"].Value = StartDateField; ndGantt.Attributes["GanttEnd"].Value = DueDateField; ndGantt.Attributes["GanttComplete"].Value = ProgressField; ndGantt.Attributes["GanttText"].Value = InfoField; if (bShowGantt) { ndGantt.Attributes["Visible"].Value = "1"; } XmlNodeList ndRows = docXml.FirstChild.SelectNodes("row"); XmlNode ndParent = doc.FirstChild.SelectSingleNode("//B"); XmlNodeList ndOldCols = docXml.FirstChild.SelectNodes("//head/column"); XmlNode ndSummary = doc.FirstChild.SelectSingleNode("//Def/D[@Name='Summary']"); if (StartDateField != "") { XmlAttribute attr = doc.CreateAttribute(StartDateField + "Formula"); attr.Value = "ganttstart()"; ndSummary.Attributes.Append(attr); } if (DueDateField != "") { XmlAttribute attr = doc.CreateAttribute(DueDateField + "Formula"); attr.Value = "ganttend()"; ndSummary.Attributes.Append(attr); } if (ProgressField != "") { XmlAttribute attr = doc.CreateAttribute(ProgressField + "Formula"); attr.Value = "ganttpercent()"; ndSummary.Attributes.Append(attr); } //PercentCompleteFormula="ganttpercent('StartDate','DueDate','d')" foreach (XmlNode ndRow in ndRows) { ProcessItems(ndParent, ndRow, ndOldCols, doc); } foreach (XmlNode ndRow in doc.FirstChild.SelectNodes("//I[@Predecessors!='']")) { processPredecessors(ndRow, doc); } foreach (DictionaryEntry de in hshLookupEnums) { XmlNode nd = doc.FirstChild.SelectSingleNode("//C[@Name='" + de.Key.ToString() + "']"); if (nd != null) { nd.Attributes["EnumKeys"].Value = ";" + string.Join(";", (int[])((ArrayList)de.Value).ToArray(Type.GetType("System.Int32"))); } } foreach (DictionaryEntry de in hshLookupEnumKeys) { XmlNode nd = doc.FirstChild.SelectSingleNode("//C[@Name='" + de.Key.ToString() + "']"); if (nd != null) { nd.Attributes["Enum"].Value = ";" + string.Join(";", (string[])((ArrayList)de.Value).ToArray(Type.GetType("System.String"))); } } XmlNode ndPag = docXml.SelectSingleNode("//call[@command='setuppaging']"); XmlNode ndCfg = doc.SelectSingleNode("//Cfg"); if (ndPag != null) { XmlAttribute attr = doc.CreateAttribute("PagInfo"); attr.Value = ndPag.InnerText; ndSummary.Attributes.Append(attr); ndCfg.Attributes.Append(attr); attr = doc.CreateAttribute("PagSize"); attr.Value = view.RowLimit.ToString(); ndSummary.Attributes.Append(attr); ndCfg.Attributes.Append(attr); } XmlAttribute attrT = doc.CreateAttribute("LinkTitleField"); attrT.Value = sTitleField; ndCfg.Attributes.Append(attrT); tb.StopTimers(); if (epmdebug != null && epmdebug == "true") { XmlNode ndNew = doc.CreateNode(XmlNodeType.Element, "I", doc.NamespaceURI); XmlAttribute attr = doc.CreateAttribute("Title"); attr.Value = tb.GetHtml(); ndNew.Attributes.Append(attr); doc.FirstChild.SelectSingleNode("//B").AppendChild(ndNew); } if (list.BaseType == SPBaseType.DocumentLibrary) { XmlAttribute attr = doc.CreateAttribute("NameCol"); attr.Value = "FileLeafRef"; ndCfg.Attributes.Append(attr); attr = doc.CreateAttribute("MainCol"); attr.Value = "FileLeafRef"; ndCfg.Attributes.Append(attr); } else { XmlAttribute attr = doc.CreateAttribute("NameCol"); attr.Value = "Title"; ndCfg.Attributes.Append(attr); attr = doc.CreateAttribute("MainCol"); attr.Value = "Title"; ndCfg.Attributes.Append(attr); } data = doc.OuterXml; }
public static List <SPFieldGeneral> GetFieldsList(string listId) { SPWeb web; try { web = SPContext.Current.Web; } catch (Exception) { web = new SPSite("http://net-sp:100").OpenWeb(); } SPList list = web.Lists[new Guid(listId)]; List <SPFieldGeneral> list2 = new List <SPFieldGeneral>(); string str = HttpContext.Current.Request.Url.ToString(); foreach (SPField field in list.Fields) { if ((field.FromBaseType && (field.InternalName != "Title")) && (field.InternalName != "ID")) { continue; } SPFieldGeneral item = new SPFieldGeneral(); string str2 = field.Type.ToString(); item.Guid = field.Id; item.InternalName = field.InternalName; item.Title = field.Title; item.DefaultValue = field.DefaultValue; item.IsRequire = field.Required; item.Type = field.TypeAsString; switch (field.TypeAsString) { case "Text": item.MaxLength = ((SPFieldText)field).MaxLength; break; case "Number": item.MaxValue = ((SPFieldNumber)field).MaximumValue; item.MinValue = ((SPFieldNumber)field).MinimumValue; item.ShowAsPercentage = ((SPFieldNumber)field).ShowAsPercentage; break; case "Lookup": item.LookupList = ((SPFieldLookup)field).LookupList.Replace("{", "").Replace("}", ""); item.LookupTitleField = "Title"; item.LookupValueField = "ID"; item.AllowMultipleValue = ((SPFieldLookup)field).AllowMultipleValues; break; case "LookupMulti": item.LookupList = ((SPFieldLookup)field).LookupList.Replace("{", "").Replace("}", ""); item.LookupTitleField = "Title"; item.LookupValueField = "ID"; item.AllowMultipleValue = ((SPFieldLookup)field).AllowMultipleValues; break; case "RelatedCustomLookupQuery": item.LookupList = field.GetCustomProperty("ListNameLookup").ToString().Replace("{", "").Replace("}", ""); item.LookupTitleField = field.GetCustomProperty("FieldTitleLookup").ToString(); item.LookupValueField = field.GetCustomProperty("FieldValueLookup").ToString(); item.RelatedFields = field.GetCustomProperty("RelatedFields").ToString().Split(new char[] { '|' }); item.Query = field.GetCustomProperty("QueryLookup").ToString(); break; case "MasterDetail": item.LookupList = field.GetCustomProperty("ListNameLookup").ToString(); item.RelatedFields = field.GetCustomProperty("RelatedFields").ToString().Split(new char[] { '|' }); item.MasterLookupName = field.GetCustomProperty("MasterFieldNameLookup").ToString(); break; case "CustomComputedField": item.LookupList = field.GetCustomProperty("ListNameQuery").ToString(); item.LookupTitleField = field.GetCustomProperty("FieldNameQuery").ToString(); item.Query = field.GetCustomProperty("TextQuery").ToString(); item.AggregationFunction = field.GetCustomProperty("AggregatorFunction").ToString(); break; case "Choice": { SPFieldChoice choice = (SPFieldChoice)field; item.options = new List <string>(); foreach (string str3 in choice.Choices) { item.options.Add(str3); } item.DefaultValue = ((SPFieldChoice)field).DefaultValue; item.AllowMultipleValue = ((SPFieldChoice)field).ListItemMenu; break; } case "MultiChoice": { SPFieldMultiChoice choice2 = (SPFieldMultiChoice)field; item.options = new List <string>(); foreach (string str3 in choice2.Choices) { item.options.Add(str3); } item.AllowMultipleValue = ((SPFieldMultiChoice)field).ListItemMenu; break; } } list2.Add(item); } return(list2); }
public static void UpdateFieldValue(this SPListItem item, SPField updatedField, string data) { if (string.IsNullOrEmpty(data) || data.CompareTo(";#") == 0) { return; } switch (updatedField.Type) { case SPFieldType.Boolean: item[updatedField.Id] = Convert.ToBoolean(data); break; case SPFieldType.File: case SPFieldType.Calculated: case SPFieldType.Computed: case SPFieldType.Currency: case SPFieldType.Integer: case SPFieldType.Note: case SPFieldType.Number: case SPFieldType.Text: item[updatedField.Id] = data; break; case SPFieldType.Choice: SPFieldChoice fieldChoice = (SPFieldChoice)updatedField; item[updatedField.Id] = data; break; case SPFieldType.DateTime: SPFieldDateTime fieldDate = (SPFieldDateTime)updatedField; item[updatedField.Id] = Convert.ToDateTime(data); break; case SPFieldType.Lookup: SPFieldLookup fieldLookup = (SPFieldLookup)updatedField; if (fieldLookup.AllowMultipleValues) { SPFieldLookupValueCollection multiValues = new SPFieldLookupValueCollection(); foreach (var s in data.Split("|".ToCharArray())) { multiValues.Add(new SPFieldLookupValue(s)); } item[updatedField.Id] = multiValues; } else { //int id = fieldLookup.GetLookupIdFromValue(data); SPFieldLookupValue singleLookupValue = new SPFieldLookupValue(data); item[updatedField.Id] = singleLookupValue; } break; case SPFieldType.MultiChoice: SPFieldMultiChoice fieldMultichoice = (SPFieldMultiChoice)updatedField; string[] items = data.Split("|".ToCharArray()); SPFieldMultiChoiceValue values = new SPFieldMultiChoiceValue(); foreach (string choice in items) { values.Add(choice); } item[updatedField.Id] = values; break; case SPFieldType.User: SPFieldUser fieldUser = (SPFieldUser)updatedField; SPFieldUserValueCollection fieldValues = new SPFieldUserValueCollection(); string[] entities = data.Split("|".ToCharArray()); foreach (string entity in entities) { SPUser user = item.Web.EnsureUser(entity.Split(";#".ToCharArray())[2]); if (user != null) { fieldValues.Add(new SPFieldUserValue(item.Web, user.ID, user.Name)); } } item[updatedField.Id] = fieldValues; break; } }