static void TestDetailView(SPWeb spWeb) { SPList listMaster = spWeb.Lists["Чернетки вхідних документів"], listDetail = spWeb.Lists["Рух чернеток вхідних документів"]; string fieldNameInMaster = "dn_ct_Movings", fieldNameInDetail = "dn_ct_Parent", fieldNameExecutionResult = "dn_ct_ExecutionResult"; foreach (SPListItem item in listMaster.Items) { SPField field = item.Fields.GetFieldByInternalName(fieldNameInMaster); } foreach (SPListItem item in listDetail.Items) { SPField field = item.Fields.GetFieldByInternalName(fieldNameInDetail); SPFieldLookupValue spFieldLookupValue = (SPFieldLookupValue)item[fieldNameInDetail]; field = item.Fields.GetFieldByInternalName(fieldNameExecutionResult); object tmpObject = field.GetFieldValue((string)item[fieldNameExecutionResult]); spFieldLookupValue = (SPFieldLookupValue)tmpObject; } }
public static object GetValue(this SPListItemVersion itemVersion, Guid fieldId) { SPField field = itemVersion.Fields[fieldId]; object value = itemVersion[field.InternalName]; return(value != null?field.GetFieldValue(value.ToString()) : null); }
public static object GetValue(this SPListItem item, Guid fieldId) { SPField field = item.Fields[fieldId]; object value = item[field.Id]; return(value != null?field.GetFieldValue(value.ToString()) : null); }
public static object GetValue(this SPListItem item, string fieldName) { SPField field = item.Fields.GetField(fieldName); object value = item[field.Id]; return(value != null?field.GetFieldValue(value.ToString()) : null); }
static void TestLookupFields(SPWeb spWeb) { SPList //list = spWeb.Lists["Внутрішні документи"]; //list = spWeb.Lists["Підрозділ організації"]; list = spWeb.Lists["Рух вхідних документів"]; SPListItem item = list.Items[0]; string fieldName = "dn_ct_Recipient"; SPField //field = item.Fields.GetFieldByInternalName("dn_ct_AuthorExecutor"); //field = item.Fields["Автор-виконавець"]; field = item.Fields.GetFieldByInternalName(fieldName); object tmpObject = item[fieldName]; SPField spField = item[fieldName] as SPField; SPFieldLookup spFieldLookup = item[fieldName] as SPFieldLookup; SPFieldLookupValue spFieldLookupValue = item[fieldName] as SPFieldLookupValue; SPFieldUser spFieldUser = item[fieldName] as SPFieldUser; SPFieldUserValue spFieldUserValue = item[fieldName] as SPFieldUserValue; if ((spFieldUserValue = field.GetFieldValue(tmpObject.ToString()) as SPFieldUserValue) != null) { Console.WriteLine("LookupId: {0}", spFieldUserValue.LookupId); } SPFieldUserValueCollection spFieldUserValueCollection = item[fieldName] as SPFieldUserValueCollection; if ((spFieldUserValueCollection = field.GetFieldValue(tmpObject.ToString()) as SPFieldUserValueCollection) != null) { foreach (SPFieldUserValue _spFieldUserValue_ in spFieldUserValueCollection) { Console.WriteLine("LookupId: {0}, LookupValue: {1}, User.ID: {2}, User.Name: {3}", _spFieldUserValue_.LookupId, _spFieldUserValue_.LookupValue, _spFieldUserValue_.User.ID, _spFieldUserValue_.User.Name); } } }
static void TestContentType(SPWeb spWeb) { foreach (SPContentType contentType in spWeb.AvailableContentTypes) { SPContentTypeId ItemContentTypeId = new SPContentTypeId("0x01"), MovingContentTypeId = new SPContentTypeId("0x010036C09CCB6A04462589FAF08349A3FB96"), IncomingDocProjectMovingContentTypeId = new SPContentTypeId("0x010036C09CCB6A04462589FAF08349A3FB96002479A5F6DE3147b38F01AD5857AC159B"), IncomingDocMovingContentTypeId = new SPContentTypeId("0x010036C09CCB6A04462589FAF08349A3FB9600F982305F9274494b83ECC7EFD1AA07E8"); if (contentType.Id != ItemContentTypeId && contentType.Id != MovingContentTypeId && contentType.Id != IncomingDocProjectMovingContentTypeId && contentType.Id != IncomingDocMovingContentTypeId) { continue; } Console.WriteLine("{0} {1}", contentType.Id, contentType.Name); Console.WriteLine("Fields:"); foreach (SPField field in contentType.Fields) { Console.WriteLine("{0} {1}", field.Title, field.Id); } Console.WriteLine(); } ShowFields(spWeb.Lists["Рух чернеток вхідних документів"]); ShowFields(spWeb.Lists["Рух вхідних документів"]); string listName = "TaskReports", //"Чернетки вхідних документів", fieldName = "ContentType"; SPList list = spWeb.Lists[listName]; foreach (SPListItem item in list.Items) { SPField field = item.Fields.GetFieldByInternalName(fieldName); object tmpObject = item[fieldName], tmpObjectII = field.GetFieldValue((string)item[fieldName]); SPFieldChoice spFieldChoice = tmpObjectII as SPFieldChoice; SPContentType spContentType = item.ContentType; } }
static int?GetFieldUserValue(SPListItem item, string fieldName) { int? value = null; SPField field = item.Fields.GetFieldByInternalName(fieldName); SPFieldUserValue spFieldUserValue; if ((spFieldUserValue = field.GetFieldValue((string)item[fieldName]) as SPFieldUserValue) != null) { value = spFieldUserValue.LookupId; } return(value); }
static void TestCustomField(SPWeb spWeb) { string listName = "Чернетки внутрішніх документів", fieldName = "dn_ct_OrderItems"; SPList list = spWeb.Lists[listName]; SPQuery query = new SPQuery(); query.Query = String.Format(CultureInfo.InvariantCulture, @" <Where> <BeginsWith> <FieldRef Name='{0}'/> <Value Type='Choice'>{1}</Value> </BeginsWith> </Where> " , "ContentTypeId", "0x0100D2C12FDA49D846B7BBD35F661088B3EA003ED2EE2E00D040C08D6963B979B0DCDC006B798FA3EBA64BC089AF9C6D9AEF757E00233CFF7F13094FF2915ED5E8F627747A"); SPListItemCollection result = list.GetItems(query); foreach (SPListItem item in result) { SPContentType spContentType = item.ContentType; SPField field = item.Fields.GetFieldByInternalName(fieldName); object tmpObject = item[fieldName], tmpObjectII = field.GetFieldValue((string)item[fieldName]); } }
private static string GetCellValue(SPListItem li, SPField oField, bool bEditMode, SPWeb oWeb) { var currenvyCultureInfo = new CultureInfo(1033); string val = ""; NumberFormatInfo providerEn = new System.Globalization.NumberFormatInfo(); providerEn.NumberDecimalSeparator = "."; providerEn.NumberGroupSeparator = ","; providerEn.NumberGroupSizes = new int[] { 3 }; if (li[oField.Id] != null) { val = li[oField.Id].ToString(); switch (oField.Type) { case SPFieldType.User: if (bEditMode) { SPFieldUserValueCollection lvc = new SPFieldUserValueCollection(oWeb, val); val = ""; foreach (SPFieldUserValue lv in lvc) { val += ";" + lv.LookupId; } val = val.Trim(';'); } else { val = oField.GetFieldValueForEdit(li[oField.Id].ToString()); } break; case SPFieldType.Lookup: if (bEditMode) { SPFieldLookupValueCollection lvc = new SPFieldLookupValueCollection(val); val = ""; foreach (SPFieldLookupValue lv in lvc) { val += ";" + lv.LookupId; } val = val.Trim(';'); } else { val = oField.GetFieldValueForEdit(li[oField.Id].ToString()); } break; case SPFieldType.MultiChoice: if (bEditMode) { SPFieldMultiChoiceValue v = (SPFieldMultiChoiceValue)oField.GetFieldValue(li[oField.Id].ToString()); val = ""; for (int i = 0; i < v.Count; i++) { val += ";" + v[i]; } val = val.Trim(';'); } else { oField.GetFieldValueForEdit(val); } break; case SPFieldType.Calculated: val = li[oField.Id].ToString(); if (oField.Description == "Indicator" || val.ToLower().EndsWith(".gif") || val.ToLower().EndsWith(".png") || val.ToLower().EndsWith(".jpg")) { val = "<img src=\"/_layouts/15/images/" + oField.GetFieldValueAsText(val) + "\">"; } else { val = val.Substring(val.IndexOf(";#") + 2); } break; case SPFieldType.Currency: try { val = ((double)li[oField.Id]).ToString(currenvyCultureInfo.NumberFormat); } catch { val = "0"; } break; case SPFieldType.Number: SPFieldNumber fNum = (SPFieldNumber)oField; if (fNum.ShowAsPercentage) { try { val = (float.Parse(val) * 100).ToString(providerEn); } catch { } } else { //if (bEditMode) //{ // val = li[oField.Id].ToString(); //} //else // val = oField.GetFieldValueAsText(li[oField.Id].ToString()); try { val = ((double)li[oField.Id]).ToString(currenvyCultureInfo.NumberFormat); } catch { val = "0"; } } break; case SPFieldType.Boolean: val = "0"; try { if (li[oField.Id].ToString().ToLower() == "yes" || li[oField.Id].ToString().ToLower() == "true") { val = "1"; } } catch { } break; case SPFieldType.DateTime: try { val = ((DateTime)li[oField.Id]).ToString("u"); } catch { } break; default: if (bEditMode) { val = li[oField.Id].ToString(); } else { val = oField.GetFieldValueAsText(li[oField.Id]); } break; } } return(val); }
static void TestSPQuery(SPWeb spWeb) { string listName, fieldName, fieldNameII, fieldNameIII, fieldNameIV; SPList list; SPQuery query; SPListItemCollection result; listName = "Подразделение организации"; list = spWeb.Lists[listName]; fieldName = "dn_ct_OrganizationDivisionsDivisionEmployees"; query = new SPQuery(); query.Query = string.Format(@" <Where> <Contains> <FieldRef Name='{0}' LookupId='True' /> <Value Type='Integer'>{1}</Value> </Contains> </Where> " , fieldName, 12); result = list.GetItems(query); foreach (SPListItem item in result) { object tmpObject = item["dn_ct_OrganizationDivisionsDivisionCode"]; } listName = "Шаблоны печатных форм"; list = spWeb.Lists[listName]; fieldName = "dn_ct_PrintedFormTemplateCode"; query = new SPQuery(); query.Query = string.Format(@" <Where> <Contains> <FieldRef Name='{0}'/> <Value Type='Text'>{1}</Value> </Contains> </Where> " , fieldName, "Incoming_RCC"); result = list.GetItems(query); foreach (SPListItem item in result) { SPFile spFile = item.File; byte[] file = spFile.OpenBinary(); } listName = "Чернетки вхідних документів"; list = spWeb.Lists[listName]; fieldName = "ContentTypeId"; // FieldMetadata.ContentTypeIdInternalName fieldNameII = "ContentType"; // FieldMetadata.ContentTypeInternalName query = new SPQuery(); query.Query = string.Format(@" <Where> <BeginsWith> <FieldRef Name='{0}'/> <Value Type='Choice'>{1}</Value> </BeginsWith> </Where> " , fieldName, "0x0100D2C12FDA49D846B7BBD35F661088B3EA007D4CED701F8B4D7483806C2393C6CDEB" /*ContentTypeMetadata.CitizenAppealProjectContentTypeId*/); result = list.GetItems(query); foreach (SPListItem item in result) { SPField field = item.Fields.GetFieldByInternalName(fieldNameII); object tmpObject = field.GetFieldValue((string)item[fieldNameII]); if (tmpObject != null) { ; } Console.WriteLine("{{ID: {0}, {1}: {2}, {3}: {4}}}", item.ID, fieldNameII, item[fieldNameII], fieldName, item[fieldName]); } listName = "Чернетки вхідних документів"; list = spWeb.Lists[listName]; fieldName = "ContentTypeId"; // FieldMetadata.ContentTypeIdInternalName fieldNameII = "ContentType"; // FieldMetadata.ContentTypeInternalName query = new SPQuery(); query.Query = string.Format(@" <Where> <Or> <BeginsWith> <FieldRef Name='{0}'/> <Value Type='Choice'>{1}</Value> </BeginsWith> <BeginsWith> <FieldRef Name='{0}'/> <Value Type='Choice'>{2}</Value> </BeginsWith> </Or> </Where> " , fieldName, "0x0100D2C12FDA49D846B7BBD35F661088B3EA00AEDA8C185B5E48FCA1D32347189F100E" /*ContentTypeMetadata.IncomingDocumentProjectContentTypeId*/, "0x0100D2C12FDA49D846B7BBD35F661088B3EA00ED44EBCA97D449E3B8D3FDF9E7318BA7" /*ContentTypeMetadata.CitizenProjectContentTypeId*/); result = list.GetItems(query); foreach (SPListItem item in result) { SPField field = item.Fields.GetFieldByInternalName(fieldNameII); object tmpObject = field.GetFieldValue((string)item[fieldNameII]); if (tmpObject != null) { ; } Console.WriteLine("{{ID: {0}, {1}: {2}, {3}: {4}}}", item.ID, fieldNameII, item[fieldNameII], fieldName, item[fieldName]); } listName = "Чернетки вхідних документів"; list = spWeb.Lists[listName]; fieldName = "ContentTypeId"; // FieldMetadata.ContentTypeIdInternalName fieldNameII = "ContentType"; // FieldMetadata.ContentTypeInternalName query = new SPQuery(); query.Query = string.Format(@" <Where> <Or> <Or> <BeginsWith> <FieldRef Name='{0}'/> <Value Type='Choice'>{1}</Value> </BeginsWith> <BeginsWith> <FieldRef Name='{0}'/> <Value Type='Choice'>{2}</Value> </BeginsWith> </Or> <BeginsWith> <FieldRef Name='{0}'/> <Value Type='Choice'>{3}</Value> </BeginsWith> </Or> </Where> " , fieldName, "0x0100D2C12FDA49D846B7BBD35F661088B3EA00AEDA8C185B5E48FCA1D32347189F100E" /*ContentTypeMetadata.IncomingDocumentProjectContentTypeId*/, "0x0100D2C12FDA49D846B7BBD35F661088B3EA00ED44EBCA97D449E3B8D3FDF9E7318BA7" /*ContentTypeMetadata.CitizenProjectContentTypeId*/, "0x0100D2C12FDA49D846B7BBD35F661088B3EA007D4CED701F8B4D7483806C2393C6CDEB" /*ContentTypeMetadata.CitizenAppealProjectContentTypeId*/); result = list.GetItems(query); foreach (SPListItem item in result) { SPField field = item.Fields.GetFieldByInternalName(fieldNameII); object tmpObject = field.GetFieldValue((string)item[fieldNameII]); if (tmpObject != null) { ; } Console.WriteLine("{{ID: {0}, {1}: {2}, {3}: {4}}}", item.ID, fieldNameII, item[fieldNameII], fieldName, item[fieldName]); } listName = "Чернетки внутрішніх документів"; list = spWeb.Lists[listName]; fieldName = "dn_ct_ProjectDocument"; query = new SPQuery(); query.ViewFields = string.Format("<FieldRef Name='{0}' />", fieldName); result = list.GetItems(query); foreach (SPListItem item in result) { Console.WriteLine("{{ID: {0}, {1}: {2}}}", item.ID, fieldName, item[fieldName]); } listName = "Задачі"; list = spWeb.Lists[listName]; fieldName = "ContentTypeId"; // FieldMetadata.ContentTypeIdInternalName fieldNameII = "ContentType"; // FieldMetadata.ContentTypeInternalName query = new SPQuery(); query.Query = string.Format(@" <Where> <And> <BeginsWith> <FieldRef Name='{0}'/> <Value Type='Choice'>{1}</Value> </BeginsWith> <Eq> <FieldRef Name='dn_MainExecutor'/> <Value Type='Integer'>1</Value> </Eq> </And> </Where> " , fieldName, "0x010800C5FAF5E5260347459C440170C534AABC00CF82612503964813A9D048DD228352F8" /*ContentTypeMetadata.ExecutionResolutionTaskContentTypeId*/); result = list.GetItems(query); foreach (SPListItem item in result) { SPField field = item.Fields.GetFieldByInternalName(fieldNameII); object tmpObject = field.GetFieldValue((string)item[fieldNameII]); if (tmpObject != null) { ; } Console.WriteLine("{{ID: {0}, {1}: {2}, {3}: {4}}}", item.ID, fieldNameII, item[fieldNameII], fieldName, item[fieldName]); } listName = "Вхідні документи [v2]"; list = spWeb.Lists[listName]; fieldName = "dn_ct_RegNumber"; query = new SPQuery(); query.Query = String.Format(CultureInfo.InvariantCulture, @" <Where> <IsNotNull> <FieldRef Name='{0}'/> </IsNotNull> </Where> " , fieldName); result = list.GetItems(query); foreach (SPListItem item in result) { Console.WriteLine("{{ID: {0}, {1}: {2}}}", item.ID, fieldName, item[fieldName]); } listName = "Вхідні документи [v2]"; list = spWeb.Lists[listName]; fieldName = "dn_ct_RegNumber"; query = new SPQuery(); query.Query = String.Format(CultureInfo.InvariantCulture, @" <Where> <IsNull> <FieldRef Name='{0}'/> </IsNull> </Where> " , fieldName); result = list.GetItems(query); foreach (SPListItem item in result) { Console.WriteLine("{{ID: {0}, {1}: {2}}}", item.ID, fieldName, item[fieldName]); } listName = "Задачі"; list = spWeb.Lists[listName]; fieldName = "ContentTypeId"; // FieldMetadata.ContentTypeIdInternalName fieldNameII = "WorkflowListId"; fieldNameIII = "WorkflowItemId"; fieldNameIV = "ContentTypeId"; // Need for item.ContentType query = new SPQuery(); query.ViewFields = string.Format(CultureInfo.InvariantCulture, @" <FieldRef Name='{0}' /> <FieldRef Name='{1}' /> <FieldRef Name='{2}' /> " , fieldNameII, fieldNameIII, fieldNameIV); query.Query = string.Format(@" <Where> <BeginsWith> <FieldRef Name='{0}'/> <Value Type='Choice'>{1}</Value> </BeginsWith> </Where> " , fieldName, "0x010800C5FAF5E5260347459C440170C534AABC00CF82612503964813A9D048DD228352F8" /*ContentTypeMetadata.ExecutionResolutionTaskContentTypeId*/); result = list.GetItems(query); foreach (SPListItem item in result) { Console.WriteLine("{{ID: {0}, {1}: {2}, {3}: {4}}}", item.ID, fieldNameII, item[fieldNameII], fieldNameIII, item[fieldNameIII]); } }
public static SPFieldUserValue GetSPFieldUserValue(SPListItem item, string fieldName) { SPField field = item.Fields.GetField(fieldName); return((SPFieldUserValue)field.GetFieldValue(string.Concat(item[fieldName]))); }
private string getFieldVal(string field, SPItemEventProperties properties, SPList list) { try { SPField f = list.Fields.GetFieldByInternalName(field); string val = properties.AfterProperties[field].ToString(); if (f.Type == SPFieldType.DateTime) { val = val.Replace("T", " ").Replace("Z", ""); } if (val == "") { return(""); } switch (f.Type) { case SPFieldType.DateTime: try { val = f.GetFieldValue(val).ToString(); DateTime dt = DateTime.Parse(val); SPFieldDateTime dtF = (SPFieldDateTime)f; if (dtF.DisplayFormat == SPDateTimeFieldFormatType.DateOnly) { return(dt.ToShortDateString()); } else { return(dt.ToString()); } }catch {} return(""); case SPFieldType.Lookup: if (val != "") { if (val.Contains(";#")) { return(f.GetFieldValueAsText(val)); } else { SPList lookupList = properties.Web.Lists[new Guid(((SPFieldLookup)f).LookupList)]; SPListItem lookupItem = lookupList.GetItemById(int.Parse(val)); return(lookupItem[((SPFieldLookup)f).LookupField].ToString()); } } return(""); default: return(f.GetFieldValue(val).ToString()); } ; } catch { } return(""); }
private string getFieldValue(string fieldname, string value) { try { SPField oField = base.list.Fields.GetFieldByInternalName(fieldname); switch (oField.Type) { case SPFieldType.DateTime: if (value != "") { try { DateTime dt = (DateTime)oField.GetFieldValue(value); return(dt.ToString("yyyy-MM-dd HH:mm:ss")); } catch { } } return(value); case SPFieldType.Number: SPFieldNumber num = (SPFieldNumber)oField; if (num.ShowAsPercentage) { if (value.Contains("%")) { return(value.Replace("%", "")); } else { return((float.Parse(value, providerEn) * 100).ToString(providerEn)); } } else { return(float.Parse(value, providerEn).ToString(providerEn)); } case SPFieldType.Calculated: if (oField.Description == "Indicator") { if (value != "" && !value.StartsWith("<img src")) { value = "<img src=\"/_layouts/images/" + value.ToLower() + "\">"; } } SPFieldCalculated calc = (SPFieldCalculated)oField; if (calc.ShowAsPercentage) { if (value.Contains("%")) { return(value.Replace("%", "")); } else { return((float.Parse(value, providerEn) * 100).ToString(providerEn)); } } else { return(float.Parse(value, providerEn).ToString(providerEn)); } case SPFieldType.Boolean: if (value.ToLower() == "true") { return("1"); } return("0"); case SPFieldType.Note: return(HttpUtility.HtmlDecode(value)); default: switch (oField.TypeAsString) { case "TotalRollup": return(oField.GetFieldValueAsText(value)); default: return(HttpUtility.HtmlDecode(value)); } } } catch { } return(value); }