void v_Editing_v_ById_btn_Resolve_Click(object sender, EventArgs e) { try { var url = v_Editing_v_ById_tb_Url.Text; if (string.IsNullOrEmpty(url)) { v_Editing_v_ById_lbl_Message.Text = "No url"; return; } string id = null; Type type = null; SPListItem item = null; try { SPContext.Current.Web.GetListItem(url); } catch (FileNotFoundException) { } if (item != null) { id = item.UniqueId.ToString(); type = item.GetType(); } else { var list = SPContext.Current.Web.Lists.TryGetList(url); if (list != null) { id = list.ID.ToString(); type = list.GetType(); } else { } } if (!string.IsNullOrEmpty(id)) { v_Editing_v_ById_tb_Id.Text = id; v_Editing_v_ById_lbl_Type.Text = type.Name; v_Editing_v_ById_lbl_Message.Text = "Found"; } else { v_Editing_v_ById_lbl_Message.Text = "Not found"; } } catch (Exception ex) { v_Editing_v_ById_lbl_Message.Text = ex.Message; } }
public T CreateInstance(SPListItem item) { if (item == null) { return(default(T)); } Type classType = typeof(T); T classInstance = default(T); ConstructorInfo classConstructor = classType.GetConstructor(new Type[] { item.GetType() }); if (classConstructor != null) { try { classInstance = (T)classConstructor.Invoke(new object[] { item }); return(classInstance); } catch { } finally { } } return(classInstance); }