예제 #1
0
        public SPView Create(SPList list)
        {
            SPView view = list.GetView(Name);
            IEnumerable <SPField> viewFields = GetViewFields(list);

            if (view == null)
            {
                StringCollection strViewFields = new StringCollection();
                strViewFields.AddRange(viewFields.Select(vf => vf.InternalName).ToArray());
                view = list.Views.Add(Name, strViewFields, Query, RowLimit, Paged, IsDefault, ViewType, IsPersonal);
            }
            else
            {
                view.ViewFields.DeleteAll();

                foreach (SPField viewField in viewFields)
                {
                    view.ViewFields.Add(viewField);
                }

                view.Hidden      = Hidden;
                view.Scope       = Scope;
                view.Query       = Query;
                view.RowLimit    = RowLimit;
                view.Paged       = Paged;
                view.DefaultView = IsDefault;
                view.Update();
            }

            return(view);
        }
예제 #2
0
        private void CreateItemforForm()
        {
            FormWebPart wp = (FormWebPart)this.WebPart;

            List <BaseFieldControl> fields = new List <BaseFieldControl>();

            List <DesignDataSource> sources = new List <DesignDataSource>();

            if (!string.IsNullOrEmpty(wp.DataSourcesData))
            {
                sources = Utilities.DeserializeObject <List <DesignDataSource> >(wp.DataSourcesData);
            }

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                SPSite site = SPContext.Current.Site;

                site.AllowUnsafeUpdates = true;
                foreach (DesignDataSource source in sources)
                {
                    fields    = new List <BaseFieldControl>();
                    SPWeb web = site.OpenWeb(new Guid(source.WebId));
                    web.AllowUnsafeUpdates           = true;
                    SPList list                      = web.Lists[new Guid(source.ListId)];
                    SPView view                      = list.GetView(new Guid(source.ViewId));
                    SPViewFieldCollection viewfields = view.ViewFields;

                    foreach (var viewfield in viewfields)
                    {
                        BaseFieldControl formField = (BaseFieldControl)FindControl(viewfield.ToString());
                        if (formField == null)
                        {
                            continue;
                        }

                        fields.Add(formField);
                    }

                    SPListItem item = list.Items.Add();

                    foreach (BaseFieldControl Fld in fields)
                    {
                        try
                        {
                            item[Fld.FieldName] = Fld.Value;
                        }
                        catch { };
                    }
                    UpdateUserInfo(item);

                    item.Update();

                    web.AllowUnsafeUpdates = false;
                }
                site.AllowUnsafeUpdates = false;
            });
        }
        string CreateGPX(Guid listId, Guid viewId)
        {
            SPList list = Web.Lists[listId];
            SPListItemCollection itemsInView = list.GetItems(list.GetView(viewId));
            List <WayPointDrop>  waypoints   = new List <WayPointDrop>();

            //Get the Min/Max Lat/Long bounds
            double MaxLat = 0.0, MaxLon = 0.0, MinLat = 360.0, MinLon = 360.0;

            foreach (SPListItem item in itemsInView)
            {
                double lat = (double)item["Latitude"];
                double lon = (double)item["Longitude"];

                if (MaxLat < lat)
                {
                    MaxLat = lat;
                }
                if (MaxLon < lon)
                {
                    MaxLon = lon;
                }
                if (MinLat > lat)
                {
                    MinLat = lat;
                }
                if (MinLon > lon)
                {
                    MinLon = lon;
                }
                waypoints.Add(new WayPointDrop(new WayPoint((string)item["Title"], (string)item["Description"], lat, lon)));
            }

            Dictionary <string, object> values = new Dictionary <string, object>();

            values.Add("CurrentTime", DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"));
            values.Add("MaxLat", MaxLat.ToString());
            values.Add("MaxLon", MaxLon.ToString());
            values.Add("MinLon", MinLon.ToString());
            values.Add("MinLat", MinLat.ToString());
            values.Add("WayPoints", waypoints);

            Template tm = Template.Parse(gpxTemplate);

            return(tm.Render(Hash.FromDictionary(values)));
        }
        private void UpdateExistingListViews(SPList list, int level)
        {
            LogInfo($"About to update {list.Title} views.", level);
            var column = ProjectArchiverService.ArchivedColumn;
            var views  = GetAllViews(list);

            foreach (var viewId in views)
            {
                var view = list.GetView(viewId);
                try
                {
                    var query = view.Query;

                    var xml = new XmlDocument();
                    xml.LoadXml("<Query>" + (query ?? string.Empty) + "</Query>");
                    var queryNode = xml.FirstChild;
                    var whereNode = xml.SelectSingleNode("//Where");
                    if (whereNode == null)
                    {
                        whereNode          = xml.CreateElement("Where");
                        whereNode.InnerXml = ViewFilterNonArchived;
                        queryNode.AppendChild(whereNode);
                    }
                    else if (!whereNode.InnerXml.Contains(column))
                    {
                        whereNode.InnerXml = string.Format(ViewFilterJoinTemplate, whereNode.InnerXml, ViewFilterNonArchived);
                    }
                    else
                    {
                        // no change required, view already uses filter
                        continue;
                    }

                    view.Query = queryNode.InnerXml;
                    view.Update();
                }
                catch (Exception ex)
                {
                    LogError($"Could not update view '{view.Title} for list {list.Title}'.", level + 1);
                    LogError(ex.Message, level + 1);
                }
            }

            LogSuccess($"All views for {list.Title} now will exclude archived items.", level);
        }
예제 #5
0
        internal List <BaseFieldControl> FieldList(WebPart webpart)
        {
            FormWebPart wp = (FormWebPart)webpart;

            List <BaseFieldControl> fields = new List <BaseFieldControl>();

            List <DesignDataSource> sources = new List <DesignDataSource>();

            if (!string.IsNullOrEmpty(wp.DataSourcesData))
            {
                sources = Utilities.DeserializeObject <List <DesignDataSource> >(wp.DataSourcesData);
            }

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                SPSite site = SPContext.Current.Site;

                foreach (DesignDataSource source in sources)
                {
                    SPWeb web   = site.OpenWeb(new Guid(source.WebId));
                    SPList list = web.Lists[new Guid(source.ListId)];
                    SPView view = list.GetView(new Guid(source.ViewId));
                    SPViewFieldCollection viewfields = view.ViewFields;

                    foreach (var viewfield in viewfields)
                    {
                        BaseFieldControl formField = (BaseFieldControl)FindControl(viewfield.ToString());
                        //formField.ControlMode = Microsoft.SharePoint.WebControls.SPControlMode.Display;
                        if (formField == null)
                        {
                            continue;
                        }

                        fields.Add(formField);
                    }
                }
            });

            return(fields);
        }
예제 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="xml"></param>
        private void GetListItems(out string xml)
        {
            xml = string.Empty;
            SPSite                  site    = SPContext.Current.Site;
            XmlDocument             doc     = new XmlDocument();
            List <DesignDataSource> sources = new List <DesignDataSource>();

            if (!string.IsNullOrEmpty(DataSourcesData))
            {
                sources = Utilities.DeserializeObject <List <DesignDataSource> >(DataSourcesData);
            }

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                bool first = true;

                foreach (DesignDataSource source in sources)
                {
                    SPWeb web            = site.OpenWeb(new Guid(source.WebId));
                    SPList list          = web.Lists[new Guid(source.ListId)];
                    SPView view          = list.GetView(new Guid(source.ViewId));
                    view.RowLimit        = (Limit > 0) ? (uint)Limit : (uint)5;
                    SPQuery query        = new SPQuery(view);
                    query.ViewFieldsOnly = true;
                    string sxml          = list.GetItems(query).Xml;

                    if (first)
                    {
                        doc.LoadXml(sxml);

                        XmlNodeList rows = doc.SelectNodes("//z:row", NameSpaceManager(doc.NameTable));
                        foreach (XmlNode row in rows)
                        {
                            string[] fileref = row.Attributes["ows_FileRef"].Value.Split(new char[1] {
                                '#'
                            });
                            if (fileref != null)
                            {
                                string absoluteUrl = web.Url + "/" + fileref[1];
                                row.Attributes["ows_FileRef"].Value = absoluteUrl;
                            }
                        }
                        first = false;
                    }
                    else
                    {
                        XmlDocument _doc = new XmlDocument();
                        _doc.LoadXml(sxml);

                        XmlNode element    = doc.SelectSingleNode("//s:ElementType", NameSpaceManager(doc.NameTable));
                        XmlNodeList schema = _doc.SelectNodes("//s:AttributeType", NameSpaceManager(_doc.NameTable));

                        XmlNode data     = doc.SelectSingleNode("//rs:data", NameSpaceManager(doc.NameTable));
                        XmlNodeList rows = _doc.SelectNodes("//z:row", NameSpaceManager(_doc.NameTable));

                        foreach (XmlNode node in schema)
                        {
                            try
                            {
                                XmlNode importXml = doc.ImportNode(node, true);
                                element.AppendChild(importXml);
                            }
                            catch (Exception ex)
                            {
                                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                            }
                        }

                        int count = int.Parse(data.Attributes["ItemCount"].Value);
                        foreach (XmlNode row in rows)
                        {
                            try
                            {
                                string[] fileref = row.Attributes["ows_FileRef"].Value.Split(new char[1] {
                                    '#'
                                });
                                if (fileref != null)
                                {
                                    string absoluteUrl = web.Url + "/" + fileref[1];
                                    row.Attributes["ows_FileRef"].Value = absoluteUrl;
                                }

                                XmlNode importXml = doc.ImportNode(row, true);
                                data.AppendChild(importXml);
                                count++;
                            }
                            catch (Exception ex)
                            {
                                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                            }
                        }
                        data.Attributes["ItemCount"].Value = count.ToString();

                        doc.ImportNode(element, true);
                        doc.ImportNode(data, true);
                    }
                }
            });
            xml = doc.InnerXml;
        }
예제 #7
0
        public SPView Create(SPList list)
        {
            SPView view = list.GetView(Name);
            IEnumerable<SPField> viewFields = GetViewFields(list);

            if (view == null)
            {
                StringCollection strViewFields = new StringCollection();
                strViewFields.AddRange(viewFields.Select(vf => vf.InternalName).ToArray());
                view = list.Views.Add(Name, strViewFields, Query, RowLimit, Paged, IsDefault, ViewType, IsPersonal);
            }
            else
            {
                view.ViewFields.DeleteAll();

                foreach (SPField viewField in viewFields)
                {
                    view.ViewFields.Add(viewField);
                }

                view.Hidden = Hidden;
                view.Scope = Scope;
                view.Query = Query;
                view.RowLimit = RowLimit;
                view.Paged = Paged;
                view.DefaultView = IsDefault;
                view.Update();
            }

            return view;
        }
예제 #8
0
        public static void GetParametersValue(CCSCascadedLookupField field, out string WebUrl, out string LookupListName, out string FieldParentLinkedFieldName, out string FieldLookupFieldName, out string FieldViewWhereString, out string FieldViewOrderString)
        {
            using (new EnterExitLogger("Utilities:GetParametersValue function"))
            {
                WebUrl                     = "";
                LookupListName             = "";
                FieldParentLinkedFieldName = "";
                FieldLookupFieldName       = "";
                FieldViewWhereString       = "";
                FieldViewOrderString       = "";

                string webUrl                = "";
                string lookupListName        = "";
                string LookupFieldName       = "";
                string ParentLinkedFieldName = "";
                string ViewWhereString       = "";
                string ViewOrderString       = "";
                Utils.LogManager.write("Field : " + field.Title);
                SPSecurity.RunWithElevatedPrivileges(delegate
                {
                    using (SPWeb LookupWeb = SPContext.Current.Site.OpenWeb(((SPFieldLookup)field).LookupWebId))
                    {
                        SPList LookupList = LookupWeb.Lists[new Guid(field.LookupFieldListName)];
                        webUrl            = LookupWeb.Url;
                        Utils.LogManager.write("webUrl : " + webUrl);

                        lookupListName = LookupList.Title;
                        Utils.LogManager.write("lookupListName : " + lookupListName);

                        LookupFieldName = field.LookupFieldName;
                        Utils.LogManager.write("LookupFieldName : " + LookupFieldName);


                        if (!string.IsNullOrEmpty(field.GetParentLinkedColumnId()))
                        {
                            //string linked_column = field.GetProperty(CustomDropDownList.LINK_COLUMN);
                            SPField ParentLinkedField = LookupList.Fields[new Guid(field.GetParentLinkedColumnId())];
                            if (ParentLinkedField != null)
                            {
                                ParentLinkedFieldName = ParentLinkedField.InternalName;
                                Utils.LogManager.write("ParentLinkedFieldName : " + ParentLinkedFieldName);
                            }
                        }

                        if (!string.IsNullOrEmpty(field.View))
                        {
                            SPView view = LookupList.GetView(new Guid(field.View));

                            if (!String.IsNullOrEmpty(view.Query))
                            {
                                string viewQueryXML         = string.Format("<Query>{0}</Query>", view.Query);
                                XmlDocument viewQueryXMLDoc = new XmlDocument();
                                viewQueryXMLDoc.LoadXml(viewQueryXML);
                                XmlNode whereNode = viewQueryXMLDoc.DocumentElement.SelectSingleNode("Where");
                                if (whereNode != null && !string.IsNullOrEmpty(whereNode.InnerXml))
                                {
                                    ViewWhereString = whereNode.InnerXml;
                                    Utils.LogManager.write("ViewWhereString : " + ViewWhereString);
                                }

                                XmlNode orderByNode = viewQueryXMLDoc.DocumentElement.SelectSingleNode("OrderBy");
                                if (orderByNode != null && !string.IsNullOrEmpty(orderByNode.InnerXml))
                                {
                                    ViewOrderString = orderByNode.InnerXml;
                                }

                                ViewOrderString = string.Format("<OrderBy>{0}</OrderBy>", ViewOrderString);
                                Utils.LogManager.write("ViewOrderString : " + ViewOrderString);
                            }
                        }
                    }
                });

                WebUrl                     = webUrl;
                LookupListName             = lookupListName;
                FieldParentLinkedFieldName = ParentLinkedFieldName;
                FieldLookupFieldName       = LookupFieldName;
                FieldViewWhereString       = ViewWhereString;
                FieldViewOrderString       = ViewOrderString;
            }
        }
예제 #9
0
        public static void FetchAllValuesFromList(CCSCascadedLookupField field, ref List <ListItem> itemList)
        {
            using (new EnterExitLogger("Utilities:FetchAllValuesFromList function"))
            {
                SPListItemCollection matchedItemList = null;

                SPSecurity.RunWithElevatedPrivileges(delegate
                {
                    using (SPWeb LookupWeb = SPContext.Current.Site.OpenWeb(((SPFieldLookup)field).LookupWebId))
                    {
                        SPList LookupList = LookupWeb.Lists[new Guid(field.LookupFieldListName)];

                        SPQuery query        = new SPQuery();
                        query.ViewAttributes = "Scope=\"RecursiveAll\"";

                        if (!string.IsNullOrEmpty(field.View))
                        {
                            string viewQueryWhereString   = "";
                            string viewQueryOrderByString = "";

                            SPView view = LookupList.GetView(new Guid(field.View));

                            if (!String.IsNullOrEmpty(view.Query))
                            {
                                string viewQueryXML         = string.Format("<Query>{0}</Query>", view.Query);
                                XmlDocument viewQueryXMLDoc = new XmlDocument();
                                viewQueryXMLDoc.LoadXml(viewQueryXML);
                                XmlNode whereNode = viewQueryXMLDoc.DocumentElement.SelectSingleNode("Where");
                                if (whereNode != null && !string.IsNullOrEmpty(whereNode.InnerXml))
                                {
                                    viewQueryWhereString = whereNode.InnerXml;
                                }

                                XmlNode orderByNode = viewQueryXMLDoc.DocumentElement.SelectSingleNode("OrderBy");
                                if (orderByNode != null && !string.IsNullOrEmpty(orderByNode.InnerXml))
                                {
                                    viewQueryOrderByString = orderByNode.InnerXml;
                                }

                                viewQueryOrderByString = string.Format("<OrderBy>{0}</OrderBy>", viewQueryOrderByString);
                            }

                            if (!String.IsNullOrEmpty(viewQueryWhereString))
                            {
                                query.Query = "<Where>" + viewQueryWhereString + "</Where>" + viewQueryOrderByString;
                            }
                            else
                            {
                                query.Query = viewQueryOrderByString;
                            }

                            Utils.LogManager.write("Item fetch Query: " + query.Query);

                            matchedItemList = LookupList.GetItems(query);
                        }
                        else
                        {
                            matchedItemList = LookupList.Items;
                        }
                    }
                });

                Utils.LogManager.write("matchedItemList item Count: " + matchedItemList.Count);
                itemList = new List <ListItem>();
                foreach (SPListItem item in matchedItemList)
                {
                    //ListItem newItem = new ListItem(Convert.ToString(item.Fields[new Guid(field.LookupFieldName)].GetFieldValueAsText(item[new Guid(field.LookupFieldName)])), item.ID.ToString());
                    ListItem newItem = new ListItem(Convert.ToString(item.Fields.GetFieldByInternalName(field.LookupFieldName).GetFieldValueAsText(item[item.Fields.GetFieldByInternalName(field.LookupFieldName).Id])), item.ID.ToString());
                    if (!itemList.Contains(newItem))
                    {
                        itemList.Add(newItem);
                    }
                }

                Utils.LogManager.write("itemList item Count: " + itemList.Count);
            }
        }
예제 #10
0
        private void GetListItems(out string xml)
        {
            xml = string.Empty;
            SPSite                  site    = SPContext.Current.Site;
            XmlDocument             doc     = new XmlDocument();
            List <DesignDataSource> sources = new List <DesignDataSource>();

            if (!string.IsNullOrEmpty(DataSourcesData))
            {
                sources = Utilities.DeserializeObject <List <DesignDataSource> >(DataSourcesData);
            }

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                //bool first = true;

                foreach (DesignDataSource source in sources)
                {
                    SPWeb web   = site.OpenWeb(new Guid(source.WebId));
                    SPList list = web.Lists[new Guid(source.ListId)];
                    SPView view = list.GetView(new Guid(source.ViewId));
                    //view.RowLimit = 0;
                    //SPQuery query = new SPQuery(view);
                    //query.ViewFieldsOnly = true;

                    //string sxml = list.GetItems(query).Xml;
                    SPViewFieldCollection viewfields = view.ViewFields;
                    List <string> used = new List <string>();

                    foreach (var viewfield in viewfields)
                    {
                        used.Add(viewfield.ToString());
                    }

                    string dataschema = list.SchemaXml;

                    //Cleanup document
                    doc.LoadXml(dataschema);
                    XmlNode listnode     = doc.SelectSingleNode("//List", NameSpaceManager(doc.NameTable));
                    XmlNode targetfields = listnode.SelectSingleNode("//Fields", NameSpaceManager(doc.NameTable));
                    targetfields.RemoveAll();
                    XmlNode RegionalSettings = doc.SelectSingleNode("//RegionalSettings", NameSpaceManager(doc.NameTable));
                    listnode.RemoveChild(RegionalSettings);
                    XmlNode ServerSettings = doc.SelectSingleNode("//ServerSettings", NameSpaceManager(doc.NameTable));
                    listnode.RemoveChild(ServerSettings);

                    //Get All Node again
                    XmlDocument schemadoc = new XmlDocument();
                    schemadoc.LoadXml(dataschema);

                    listnode               = schemadoc.SelectSingleNode("//List", NameSpaceManager(schemadoc.NameTable));
                    XmlNode fields         = listnode.SelectSingleNode("//Fields", NameSpaceManager(schemadoc.NameTable));
                    XmlNodeList fieldnodes = fields.SelectNodes("//Field", NameSpaceManager(schemadoc.NameTable));

                    foreach (XmlNode field in fieldnodes)
                    {
                        XmlNode namenode        = field.Attributes["Name"];
                        XmlNode displaynamenode = field.Attributes["DisplayName"];
                        XmlNode staticnamenode  = field.Attributes["StaticName"];
                        XmlNode hiddennode      = field.Attributes["Hidden"];

                        string name = string.Empty;
                        if (namenode != null)
                        {
                            name = namenode.Value;
                        }

                        string staticname = string.Empty;
                        if (staticnamenode != null)
                        {
                            staticname = staticnamenode.Value;
                        }

                        string displayname = string.Empty;
                        if (displaynamenode != null)
                        {
                            displayname = displaynamenode.Value;
                        }

                        bool hidden = false;
                        if (hiddennode != null)
                        {
                            hidden = Boolean.Parse(hiddennode.Value);
                        }

                        if (used.Contains(name) || used.Contains(displayname) || used.Contains(staticname))
                        {
                            try
                            {
                                if (field.ParentNode == fields)
                                {
                                    XmlNode importNode = doc.ImportNode(field, true);
                                    targetfields.AppendChild(importNode);

                                    if (importNode.ParentNode == targetfields)
                                    {
                                        if (hiddennode == null)
                                        {
                                            XmlAttribute hiddenAttribute = importNode.OwnerDocument.CreateAttribute("Hidden");
                                            hiddenAttribute.Value        = Boolean.FalseString;
                                            importNode.Attributes.Append(hiddenAttribute);
                                        }

                                        XmlNode requirednode = importNode.Attributes["Required"];

                                        if (requirednode == null && importNode.ParentNode == targetfields)
                                        {
                                            XmlAttribute requiredAttribute = importNode.OwnerDocument.CreateAttribute("Required");
                                            requiredAttribute.Value        = Boolean.FalseString;
                                            importNode.Attributes.Append(requiredAttribute);
                                        }

                                        XmlNode groupnode = importNode.Attributes["Group"];

                                        if (groupnode == null && importNode.ParentNode == targetfields)
                                        {
                                            XmlAttribute groupAttribute = importNode.OwnerDocument.CreateAttribute("Group");
                                            groupAttribute.Value        = string.Empty;
                                            importNode.Attributes.Append(groupAttribute);
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                ex.ToString();
                            }
                        }
                    }
                }
            });
            xml = doc.InnerXml;
        }
예제 #11
0
        private void SetListFormFields(Control canvas)
        {
            List <DesignDataSource> sources = new List <DesignDataSource>();

            if (!string.IsNullOrEmpty(DataSourcesData))
            {
                sources = Utilities.DeserializeObject <List <DesignDataSource> >(DataSourcesData);
            }

            if (inEditMode)
            {
            }
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                SPSite site = SPContext.Current.Site;

                foreach (DesignDataSource source in sources)
                {
                    SPWeb web   = site.OpenWeb(new Guid(source.WebId));
                    SPList list = web.Lists[new Guid(source.ListId)];
                    SPView view = list.GetView(new Guid(source.ViewId));
                    SPViewFieldCollection viewfields = view.ViewFields;

                    foreach (var viewfield in viewfields)
                    {
                        if (list.Fields.ContainsField(viewfield.ToString()))
                        {
                            try
                            {
                                string fieldname = viewfield.ToString().Replace("_x0020_", " ");
                                SPField field    = list.Fields.GetField(fieldname);
                                FormField fld    = new FormField();

                                if (inEditMode && Page.IsPostBack)
                                //if (DesignMode)// && Page.IsPostBack)
                                {
                                    fld.ControlMode = SPControlMode.Display;
                                }
                                else
                                {
                                    fld.ControlMode = SPControlMode.New;
                                }

                                //fld.ControlMode = SPControlMode.New;

                                fld.ListId    = list.ID;
                                fld.FieldName = field.InternalName;
                                fld.ID        = field.InternalName;
                                fld.DisableInputFieldLabel = true;

                                fld.InDesign = inEditMode;
                                fld.IsValid  = inEditMode;

                                try
                                {
                                    if (!string.IsNullOrEmpty(field.DefaultValue))
                                    {
                                        if (field.FieldValueType == typeof(Boolean))
                                        {
                                            bool isbool         = false;
                                            fld.Value           = (Boolean.TryParse(field.DefaultValue, out isbool));
                                            fld.InputFieldLabel = string.Empty;
                                        }
                                        else
                                        {
                                            fld.Value = field.DefaultValue;
                                        }
                                    }
                                }
                                catch (Exception)
                                {
                                }

                                canvas.Controls.Add(fld);

                                if (field.Required)
                                {
                                    InputFormRequiredFieldValidator required = new InputFormRequiredFieldValidator();
                                    required.ID = "required_" + fld.ClientID;
                                    required.ControlToValidate = fld.ClientID;
                                    required.ValidationGroup   = fld.ClientID;
                                    required.ErrorMessage      = field.ValidationMessage;
                                    //required.EnableClientScript = true;
                                    required.BreakAfter  = true;
                                    required.BreakBefore = false;
                                    required.Display     = System.Web.UI.WebControls.ValidatorDisplay.Dynamic;
                                    canvas.Controls.Add(required);
                                }

                                if (field.Type == SPFieldType.Number)
                                {
                                    SPFieldNumber Number = (SPFieldNumber)field;
                                    if (Number.MinimumValue != Double.MinValue && Number.MaximumValue != Double.MaxValue)
                                    {
                                        InputFormRangeValidator range = new InputFormRangeValidator();
                                        range.ID = "range_" + fld.ClientID;
                                        range.ControlToValidate = fld.ClientID;
                                        range.ValidationGroup   = fld.ClientID;
                                        range.ErrorMessage      = field.ValidationMessage;
                                        //range.EnableClientScript = true;
                                        range.BreakAfter   = true;
                                        range.BreakBefore  = false;
                                        range.Display      = System.Web.UI.WebControls.ValidatorDisplay.Dynamic;
                                        range.MaximumValue = Number.MaximumValue.ToString();
                                        range.MinimumValue = Number.MinimumValue.ToString();
                                        range.Type         = System.Web.UI.WebControls.ValidationDataType.Double;
                                        canvas.Controls.Add(range);
                                    }
                                }

                                if (field.Type == SPFieldType.Currency)
                                {
                                    SPFieldCurrency Currency = (SPFieldCurrency)field;
                                    if (Currency.MaximumValue != Double.MaxValue && Currency.MinimumValue != Double.MinValue)
                                    {
                                        InputFormRangeValidator range = new InputFormRangeValidator();
                                        range.ID = "range_" + fld.ClientID;
                                        range.ControlToValidate = fld.ClientID;
                                        range.ValidationGroup   = fld.ClientID;
                                        range.ErrorMessage      = field.ValidationMessage;
                                        //range.EnableClientScript = true;
                                        range.BreakAfter   = true;
                                        range.BreakBefore  = false;
                                        range.Display      = System.Web.UI.WebControls.ValidatorDisplay.Dynamic;
                                        range.MaximumValue = Currency.MaximumValue.ToString();
                                        range.MinimumValue = Currency.MinimumValue.ToString();
                                        range.Type         = System.Web.UI.WebControls.ValidationDataType.Currency;
                                        canvas.Controls.Add(range);
                                    }
                                }

                                if (!string.IsNullOrEmpty(field.ValidationFormula))
                                {
                                    InputFormRegularExpressionValidator regex = new InputFormRegularExpressionValidator();
                                    regex.ControlToValidate = fld.ClientID;
                                    regex.ValidationGroup   = fld.ClientID;
                                    regex.ErrorMessage      = fld.ErrorMessage;
                                    regex.ErrorMessage      = field.ValidationMessage;
                                    //regex.EnableClientScript = true;
                                    regex.BreakAfter           = true;
                                    regex.BreakBefore          = false;
                                    regex.Display              = System.Web.UI.WebControls.ValidatorDisplay.Dynamic;
                                    regex.ValidationExpression = field.ValidationFormula;
                                    canvas.Controls.Add(regex);
                                }

                                /*
                                 * if (field.Type == SPFieldType.MultiChoice)
                                 * {
                                 *  InputFormCheckBoxListValidator checkboxes = new InputFormCheckBoxListValidator();
                                 *  //SPFieldMultiChoice choice = (SPFieldMultiChoice)field;
                                 *  checkboxes.ControlToValidate = fld.ClientID;
                                 *  checkboxes.ValidationGroup = fld.ClientID;
                                 *  checkboxes.ErrorMessage = fld.ErrorMessage;
                                 *  checkboxes.EnableClientScript = true;
                                 *  //checkboxes.BreakAfter = true;
                                 *  checkboxes.Display = System.Web.UI.WebControls.ValidatorDisplay.Dynamic;
                                 *  canvas.Controls.Add(checkboxes);
                                 *
                                 * }
                                 */
                            }
                            catch (Exception ex)
                            {
                                ex.Message.ToString();
                            }
                        }
                    }
                }
            });
        }
예제 #12
0
        private static void AddCalendarOverlay(SPList targetList, string viewName, string overlayViewName, string owaUrl, string exchangeUrl, SPList overlayList, string overlayName, string overlayDescription, CalendarOverlayColor color, bool alwaysShow, bool clearExisting)
        {
            var isSharePointOverlay = overlayList != null;
            var overlayViewId = string.IsNullOrEmpty(overlayViewName) ? overlayList.DefaultView.ID : overlayList.Views[overlayViewName].ID;
            var linkUrl = isSharePointOverlay ? overlayList.GetView(overlayViewId).Url : owaUrl;

            var targetView = targetList.DefaultView;
            if (!string.IsNullOrEmpty(viewName))
            {
                targetView = targetList.Views[viewName];
            }

            var xml = new XmlDocument();
            XmlElement aggregationElement = null;
            var count = 0;
            if (string.IsNullOrEmpty(targetView.CalendarSettings) || clearExisting)
            {
                xml.AppendChild(xml.CreateElement("AggregationCalendars"));
                aggregationElement = xml.CreateElement("AggregationCalendar");
                if (xml.DocumentElement != null)
                {
                    xml.DocumentElement.AppendChild(aggregationElement);
                }
            }
            else
            {
                xml.LoadXml(targetView.CalendarSettings);
                var calendars = xml.SelectNodes("/AggregationCalendars/AggregationCalendar");
                if (calendars != null)
                {
                    count = calendars.Count;
                }

                aggregationElement =
                    xml.SelectSingleNode(
                        string.Format("/AggregationCalendars/AggregationCalendar[@CalendarUrl='{0}']", linkUrl)) as XmlElement;

                if (aggregationElement == null)
                {
                    if (count >= 10)
                    {
                        throw new SPException(
                            string.Format(
                                "10 calendar ovarlays already exist for the calendar {0}.",
                                targetList.RootFolder.ServerRelativeUrl));
                    }

                    aggregationElement = xml.CreateElement("AggregationCalendar");
                    if (xml.DocumentElement != null)
                    {
                        xml.DocumentElement.AppendChild(aggregationElement);
                    }
                }
            }

            if (!aggregationElement.HasAttribute("Id"))
            {
                aggregationElement.SetAttribute("Id", Guid.NewGuid().ToString("B", CultureInfo.InvariantCulture));
            }

            aggregationElement.SetAttribute("Type", isSharePointOverlay ? "SharePoint" : "Exchange");
            aggregationElement.SetAttribute("Name", !string.IsNullOrEmpty(overlayName) ? overlayName : (overlayList == null ? string.Empty : overlayList.Title));
            aggregationElement.SetAttribute("Description", !string.IsNullOrEmpty(overlayDescription) ? overlayDescription : (overlayList == null ? string.Empty : overlayList.Description));
            aggregationElement.SetAttribute("Color", ((int)color).ToString(CultureInfo.InvariantCulture));
            aggregationElement.SetAttribute("AlwaysShow", alwaysShow.ToString());
            aggregationElement.SetAttribute("CalendarUrl", linkUrl);

            var settingsElement = aggregationElement.SelectSingleNode("./Settings") as XmlElement;
            if (settingsElement == null)
            {
                settingsElement = xml.CreateElement("Settings");
                aggregationElement.AppendChild(settingsElement);
            }

            if (isSharePointOverlay)
            {
                settingsElement.SetAttribute("WebUrl", overlayList.ParentWeb.Site.MakeFullUrl(overlayList.ParentWebUrl));
                settingsElement.SetAttribute("ListId", overlayList.ID.ToString("B", CultureInfo.InvariantCulture));
                settingsElement.SetAttribute("ViewId", overlayViewId.ToString("B", CultureInfo.InvariantCulture));
                settingsElement.SetAttribute("ListFormUrl", overlayList.Forms[PAGETYPE.PAGE_DISPLAYFORM].ServerRelativeUrl);
            }
            else
            {
                settingsElement.SetAttribute("ServiceUrl", exchangeUrl);
            }

            targetView.CalendarSettings = xml.OuterXml;
            targetView.Update();
        }
예제 #13
0
        public static void FetchMatchedValuesFromList(CustomDropDownList field, string sel_value, ref List <ListItem> item_list)
        {
            SPListItemCollection matched_items = null;
            string viewId         = string.Empty;
            bool   use_view_order = false;

            if (Convert.ToString(field.GetCustomProperty(CustomDropDownList.VIEW)) != string.Empty)
            {
                viewId         = Convert.ToString(field.GetCustomProperty(CustomDropDownList.VIEW));
                viewId         = viewId.Substring(0, viewId.IndexOf('|'));
                use_view_order = Convert.ToBoolean(field.GetCustomProperty(CustomDropDownList.SORT_BY_VIEW));
            }

            using (SPWeb w = SPContext.Current.Site.OpenWeb(((SPFieldLookup)field).LookupWebId))
            {
                SPList list1 = w.Lists[new Guid(((SPFieldLookup)field).LookupList)];

                string  linked_column = field.GetProperty(CustomDropDownList.LINK_COLUMN);
                SPField link_field    = list1.Fields[new Guid(linked_column)];

                SPQuery query = new SPQuery();
                if (string.IsNullOrEmpty(viewId))
                {
                    query.Query = "<Where><Eq><FieldRef Name='" + link_field.InternalName + "' LookupId='TRUE'/><Value Type='Lookup'>" + sel_value + "</Value></Eq></Where>";
                }
                else
                {
                    SPView view       = list1.GetView(new Guid(viewId));
                    string view_query = view.Query;
                    string item_query = "<Eq><FieldRef Name='" + link_field.InternalName + "' LookupId='TRUE'/><Value Type='Lookup'>" + sel_value + "</Value></Eq></And>";
                    if (!string.IsNullOrEmpty(view_query) && view_query.Contains("<Where>") && view_query.Contains("</Where>"))
                    {
                        int start_index = view_query.IndexOf("<Where>") + "<Where>".Length;
                        int length      = view_query.IndexOf("</Where>") - start_index;
                        view_query = view_query.Substring(start_index, length);
                        view_query = "<Where><And>" + view_query + item_query + "</Where>";
                        string view_order_query = string.Empty;
                        if (use_view_order)
                        {
                            string      xml      = string.Format("<Query>{0}</Query>", view.Query);
                            XmlDocument document = new XmlDocument();
                            document.LoadXml(xml);
                            XmlNode node = document.DocumentElement.SelectSingleNode("OrderBy");
                            if (node == null || string.IsNullOrEmpty(node.InnerXml))
                            {
                                //do nothing
                            }
                            else
                            {
                                view_order_query = node.InnerXml;
                                view_order_query = string.Format("<OrderBy>{0}</OrderBy>", view_order_query);
                            }
                            view_query += view_order_query;
                        }
                        query.Query = view_query;
                    }
                    else
                    {
                        query.Query = "<Where><Eq><FieldRef Name='" + link_field.InternalName + "' LookupId='TRUE'/><Value Type='Lookup'>" + sel_value + "</Value></Eq></Where>";
                    }
                }
                matched_items = list1.GetItems(query);
            }
            foreach (SPListItem item in matched_items)
            {
                ListItem newItem = new ListItem(Convert.ToString(item.Fields[new Guid(((SPFieldLookup)field).LookupField)].GetFieldValueAsText(item[new Guid(((SPFieldLookup)field).LookupField)])), item.ID.ToString());
                if (!item_list.Contains(newItem))
                {
                    item_list.Add(newItem);
                }
            }
        }
예제 #14
0
        public static void FetchAllValueFromLinkedList(CustomDropDownList field, ref List <ListItem> PopulateItems)
        {
            try
            {
                SPWeb  spWeb            = SPContext.Current.Site.OpenWeb(field.LookupWebId);
                SPList spFiedLookupList = spWeb.Lists[new Guid(field.LookupList)];

                if (spFiedLookupList != null && spFiedLookupList.ItemCount > 0 && spFiedLookupList.Fields.Contains(new Guid(field.LookupField)))
                {
                    SPListItemCollection Items = null;
                    string viewId = string.Empty;

                    if (Convert.ToString(field.GetCustomProperty(CustomDropDownList.VIEW)) != string.Empty)
                    {
                        viewId = Convert.ToString(field.GetCustomProperty(CustomDropDownList.VIEW));
                        viewId = viewId.Substring(0, viewId.IndexOf('|'));
                        SPView  view             = spFiedLookupList.GetView(new Guid(viewId));
                        string  view_query       = view.Query;
                        string  view_order_query = string.Empty;
                        SPQuery query            = new SPQuery();
                        query.ViewAttributes = "Scope=\"RecursiveAll\"";
                        bool use_view_order = Convert.ToBoolean(field.GetCustomProperty(CustomDropDownList.SORT_BY_VIEW));
                        if (use_view_order)
                        {
                            string      xml      = string.Format("<Query>{0}</Query>", view.Query);
                            XmlDocument document = new XmlDocument();
                            document.LoadXml(xml);
                            XmlNode node = document.DocumentElement.SelectSingleNode("OrderBy");
                            if (node == null || string.IsNullOrEmpty(node.InnerXml))
                            {
                                //do nothing
                            }
                            else
                            {
                                view_order_query = node.InnerXml;
                            }

                            view_order_query = string.Format("<OrderBy>{0}</OrderBy>", view_order_query);
                        }
                        if (view_query.Contains("<Where>"))
                        {
                            int start_index = view_query.IndexOf("<Where>") + "<Where>".Length;
                            int length      = view_query.IndexOf("</Where>") - start_index;
                            view_query  = view_query.Substring(start_index, length);
                            query.Query = "<Where>" + view_query + "</Where>" + view_order_query;
                            Items       = spFiedLookupList.GetItems(query);
                        }
                        else
                        {
                            query.Query = view_order_query;
                            Items       = spFiedLookupList.GetItems(query);
                        }
                    }
                    else
                    {
                        Items = spFiedLookupList.Items;
                    }

                    PopulateItems = new List <ListItem>();
                    foreach (SPListItem item in Items)
                    {
                        ListItem newItem = new ListItem(Convert.ToString(item.Fields[new Guid(field.LookupField)].GetFieldValueAsText(item[new Guid(field.LookupField)])), item.ID.ToString());
                        if (!PopulateItems.Contains(newItem))
                        {
                            PopulateItems.Add(newItem);
                        }
                    }
                }
            }
            catch { }
        }