Exemple #1
0
 public override string GetFieldValueAsHtml(object value)
 {
     try
     {
         var config = AssociationCollection.ParseOrDefault(SPHttpUtility.ConvertSimpleHtmlToText(value.ToString(), -1));
         int count  = config.Count;
         if (count > 0)
         {
             var sb = new StringBuilder();
             sb.Append("<table border=\"1\">");
             sb.Append(string.Format("<tr><th>#</th><th>Name</th><th>Type</th><th>Value</th></tr>"));
             foreach (var a in config)
             {
                 sb.Append(string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>", config.IndexOf(a) + 1, a.Name, a.Type, a.ValueToShortDisplay));
             }
             sb.Append("</table>");
             return(sb.ToString());
         }
         else
         {
             return("no associations");
         }
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="webSite"></param>
        /// <param name="listName"></param>
        /// <param name="colName"></param>
        /// <param name="colValue"></param>
        /// <param name="retunColumn"></param>
        /// <param name="inHTML"></param>
        /// <returns></returns>
        private string GetListValue(SPWeb webSite, string listName, string colName, string colValue, string retunColumn, bool inHTML)
        {
            string colResult = string.Empty;

            try
            {
                //SPWeb webSite = SPContext.Current.Web;
                SPList  list  = webSite.Lists[listName];
                SPQuery query = new SPQuery();

                query.Query = string.Format(
                    "<Where><Eq><FieldRef Name=\"{0}\"/>" +
                    "<Value Type=\"Text\">{1}</Value></Eq></Where>", colName, colValue);

                SPListItemCollection myItems = list.GetItems(query);
                foreach (SPListItem item in myItems)
                {
                    if (inHTML)
                    {
                        colResult = item[retunColumn].ToString();
                    }
                    else
                    {
                        colResult = SPHttpUtility.ConvertSimpleHtmlToText(item[retunColumn].ToString(), -1);
                    }
                }
            }
            catch (Exception ex)
            {
                colResult = "Error : " + ex.Message.ToString() + "  Trace : " + ex.Source.ToString();
                //LogException(ex);
            }
            return(colResult);
        }
Exemple #3
0
        private string BuildListItemHTML()
        {
            StringBuilder itemsHtml = new StringBuilder();

            itemsHtml.Append("<ul class=\"ms-core-menu-list\">");
            SPSite site = SPContext.Current.Site;
            SPWeb  web  = SPContext.Current.Web;
            SPList commonActionsList         = web.Lists.TryGetList(COMMON_ACTIONS_LIST_NAME);
            SPListItemCollection sortedItems = null;

            if (commonActionsList != null)
            {
                SPQuery q = new SPQuery();
                q.Query     = "<OrderBy><FieldRef Name=\"Order0\" Ascending=\"True\" /><FieldRef Name=\"LinkTitle\" Ascending=\"True\" /></OrderBy>";
                sortedItems = commonActionsList.GetItems(q);
            }

            if (sortedItems != null)
            {
                for (int i = 0; i < sortedItems.Count; i++)
                {
                    string itemText    = string.Empty;
                    string description = string.Empty;
                    string linkUrl     = string.Empty;
                    string newWindow   = string.Empty;
                    string imageUrl    = string.Empty;
                    string onclick     = string.Empty;

                    bool isPopup = false;

                    // get title
                    if (FieldExists(COMMON_ACTIONS_LIST_NAME, sortedItems[i], COL_TITLE))
                    {
                        object titleField = sortedItems[i][commonActionsList.Fields.GetFieldByInternalName(COL_TITLE).Id];

                        if (titleField != null && !string.IsNullOrEmpty(titleField.ToString()))
                        {
                            itemText = titleField.ToString();
                        }
                    }

                    // get description
                    if (FieldExists(COMMON_ACTIONS_LIST_NAME, sortedItems[i], COL_DESCRIPTION))
                    {
                        description = "Description for common action " + (i + 1).ToString();
                        object descriptionField = sortedItems[i][commonActionsList.Fields.GetFieldByInternalName(COL_DESCRIPTION).Id];

                        if (descriptionField != null && !string.IsNullOrEmpty(SPHttpUtility.ConvertSimpleHtmlToText(descriptionField.ToString(), -1)))
                        {
                            description = SPHttpUtility.ConvertSimpleHtmlToText(descriptionField.ToString(), -1);
                        }
                    }

                    if (FieldExists(COMMON_ACTIONS_LIST_NAME, sortedItems[i], COL_NEW_WINDOW))
                    {
                        string openInNewWindowValue = string.Empty;
                        if (sortedItems[i][commonActionsList.Fields.GetFieldByInternalName(COL_NEW_WINDOW).Id] != null)
                        {
                            openInNewWindowValue = sortedItems[i][commonActionsList.Fields.GetFieldByInternalName(COL_NEW_WINDOW).Id].ToString();
                        }

                        if (!string.IsNullOrEmpty(openInNewWindowValue))
                        {
                            switch (openInNewWindowValue)
                            {
                            case "Same window":
                                newWindow = "_self";
                                break;

                            case "New window":
                                newWindow = "_blank";
                                break;

                            case "Popup":
                                newWindow = "";
                                isPopup   = true;
                                break;

                            default:
                                newWindow = "_self";
                                break;
                            }
                        }
                        else
                        {
                            newWindow = "_self";
                        }
                    }

                    // get link Url
                    if (FieldExists(COMMON_ACTIONS_LIST_NAME, sortedItems[i], COL_URL))
                    {
                        if (sortedItems[i][commonActionsList.Fields.GetFieldByInternalName(COL_URL).Id] != null)
                        {
                            linkUrl = new SPFieldUrlValue(sortedItems[i][commonActionsList.Fields.GetFieldByInternalName(COL_URL).Id].ToString()).Url;
                            if (linkUrl.IndexOf('?') != -1)
                            {
                                linkUrl += ("&source=" + _requestUrl);
                            }
                            else
                            {
                                linkUrl += ("?source=" + _requestUrl);
                            }
                        }

                        if (linkUrl.StartsWith("/", StringComparison.CurrentCultureIgnoreCase))
                        {
                            linkUrl = (SPContext.Current.Web.ServerRelativeUrl == "/" ? "" : SPContext.Current.Web.ServerRelativeUrl) + linkUrl;
                        }

                        if (isPopup)
                        {
                            string popupUrl = linkUrl;
                            onclick = "javascript:var options = { url:'" + linkUrl + "', title: '" + itemText + "' }; SP.SOD.execute('SP.UI.Dialog.js', 'SP.UI.ModalDialog.showModalDialog', options); return false;";
                            linkUrl = "#";
                        }
                    }

                    // get image url from link field
                    if (FieldExists(COMMON_ACTIONS_LIST_NAME, sortedItems[i], COL_IMAGE_URL))
                    {
                        if (sortedItems[i][commonActionsList.Fields.GetFieldByInternalName(COL_IMAGE_URL).Id] != null)
                        {
                            imageUrl = new SPFieldUrlValue(sortedItems[i][commonActionsList.Fields.GetFieldByInternalName(COL_IMAGE_URL).Id].ToString()).Url;
                        }

                        if (string.IsNullOrEmpty(imageUrl))
                        {
                            imageUrl = "/_layouts/EPMLive/images/WESite.png";
                        }
                    }

                    itemsHtml.Append(String.Format(LIST_ITEM_HTML, "MenuItem" + i, description, itemText, imageUrl, linkUrl, newWindow, onclick));
                }

                itemsHtml.Append("</ul>");
            }

            return(itemsHtml.ToString());
        }