zoukankan      html  css  js  c++  java
  • SharePointWebControls帮助类

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.SharePoint.WebControls;
    using System.Web.UI.WebControls;
    using System.Web.UI;
    using Microsoft.SharePoint;

    namespace X.WebParts.UploadDocument
    {
        class SharePointWebControls
        {
            /// <summary>
            /// 返回控件
            /// </summary>
            public static Control GetSharePointControls(SPField field, SPList list, SPListItem item, SPControlMode mode)
            {
                // 检查是否隐藏
                if (field == null || field.FieldRenderingControl == null || field.Hidden) return null;

                try
                {
                    BaseFieldControl webControl = field.FieldRenderingControl;
                    webControl.ListId = list.ID;
                    webControl.ItemId = item.ID;
                    webControl.FieldName = field.Title;
                    webControl.ID = GetControlID(field);
                    webControl.ControlMode = mode;

                    return webControl;
                }
                catch (Exception ex)
                {
                    var errorLabel = new Label
                    {
                        ID = "ErrorLabel",
                        Text = string.Format("控件错误:<br/>{0}", ex)
                    };
                    return errorLabel;
                }
            }

            /// <summary>
            /// 返回控件对应的值
            /// </summary>
            public static object GetSharePointControlValue(ControlCollection Controls, SPField field)
            {
                if (Controls == null)
                {
                    return null;
                }

                // 控件ID
                string controlID = GetControlID(field);

                foreach (Control control in Controls)
                {
                    Control returnObject = control.FindControl(controlID);
                    // 取值
                    if (returnObject != null && returnObject is BaseFieldControl)
                    {
                        return ((BaseFieldControl)returnObject).Value;
                    }
                }

                return null;
            }


            /// <summary>
            /// 返回控件对应的值
            /// </summary>
            public static object GetSharePointControlValue(Control Control, string controlID)
            {
                if (Control == null)
                {
                    return null;
                }
                Control returnObject = Control.FindControl(controlID);
                if (returnObject != null && returnObject is BaseFieldControl)
                {
                    return ((BaseFieldControl)returnObject).Value;
                }

                return null;
            }


            public static Control FindControlRecursive(Control control, string controlID)
            {
                Control returnObject = control.FindControl(controlID);
                return returnObject;
            }

            private static string GetControlID(SPField field)
            {
                // unique id
                return System.Guid.NewGuid().ToString() + field.InternalName;
            }
        }
    }

    关于作者: 王昕(QQ:475660) 在广州工作生活30余年。十多年开发经验,在Java、即时通讯、NoSQL、BPM、大数据等领域较有经验。
    目前维护的开源产品:https://gitee.com/475660
  • 相关阅读:
    bzoj 3709: [PA2014]Bohater【贪心】
    bzoj 3714: [PA2014]Kuglarz【最小生成树】
    bzoj 2216: [Poi2011]Lightning Conductor【决策单调性dp+分治】
    bzoj 2087: [Poi2010]Sheep【凸包+极角排序+dp】
    bzoj 3830: [Poi2014]Freight【dp】
    bzoj 3930: [CQOI2015]选数【快速幂+容斥】
    bzoj 1717: [Usaco2006 Dec]Milk Patterns 产奶的模式【后缀自动机】
    bzoj 1614: [Usaco2007 Jan]Telephone Lines架设电话线【二分+spfa】
    bzoj 1640||1692: [Usaco2007 Dec]队列变换【后缀数组】
    bzoj 1612: [Usaco2008 Jan]Cow Contest奶牛的比赛【Floyd】
  • 原文地址:https://www.cnblogs.com/starcrm/p/1562662.html
Copyright © 2011-2022 走看看