mhinze.com

links etc.




    Archive for the 'Sharepoint 2003' Category

    sharepoint 2003: portal listings in code

    Thursday, April 12th, 2007

    seems simple enough huh?  well i am learning as i go on this 2003 object model stuff and couldn't find anything on this easily. so maybe this will help someone.

    code to get a portal listing, portal listings

    using Microsoft.SharePoint.Portal;
    using Microsoft.SharePoint.Portal.SiteData;
     

    Area area = AreaManager.GetArea(PortalContext.Current, new Guid(areaGuid));
    foreach (AreaListing listing in area.Listings)
    {
        // do stuff
    }
     
     
    Technorati tags: , ,

    sharepoint 2003 OM code to sort Link List items

    Friday, April 6th, 2007

    weekending in east texas

    and ive had just about enough of the internets and asp.net and sharepoint and seo and all that for a few days.

     

    so thank you for keeping up with me here and have a very happy Easter.  see you next week.

     

    by the way, i wrote a little class yesterday.  might be useful if you want to sort or order the SPListItems in a "Links" List in sharepoint 2003. 

    yes that's a float - a float not an int!  =)

     

        #region SPListItemOrderer : IComparer
        public class SPListItemOrderer : IComparer
        {
            public int Compare(object x, object y)
            {
                SPListItem sx;
                SPListItem sy;
    
                if (x is SPListItem)
                {
                    sx = x as SPListItem;
                }
                else throw new ArgumentException("Object is not of type SPListItem");
    
                if (y is SPListItem)
                {
                    sy = y as SPListItem;
                }
                else throw new ArgumentException("Object is not of type SPListItem");
    
                if (sx["Order"] != null || sy["Order"] != null)
                    return float.Parse(sx["Order"].ToString()).CompareTo(float.Parse(sy["Order"].ToString()));
                else throw new ArgumentException("SPListItem does not have an order field");
            }
        }
        #endregion

     

     

    gah, oh ok, ok.. here's the usage:

     

     
    // get an array from the collection so we can sort it
    ArrayList items = new ArrayList();
    foreach (SPListItem item in theList.Items)
    {
        items.Add(item);
    }
    SPListItem[] sortableItems = (SPListItem[]) items.ToArray(typeof(SPListItem));
    try
    {
        Array.Sort(sortableItems, new SPListItemOrderer());
    } catch { /* do not sort */ }

     

    just in case you want to do something like this ( by the way that inumerating the fields code was a pain!):

     
    foreach (SPListItem si in sortableItems)
    {
        try
        {
            // debugging stuff here
            //foreach (SPField f in si.Fields)
            //{
            //    try
            //    {
            //        strOut += string.Format("<!– {0} : {1} –>\n", f.Title, si[f.Title].ToString());
            //    }
            //    catch { }
            //}
    
            // the URL item has two fields, comma separated
            string itemurl = System.Web.HttpUtility.UrlPathEncode(si["URL"].ToString().Split(',')[0].Trim());
            string itemname = si["URL"].ToString().TrimStart(itemurl.ToCharArray()).TrimStart(',').Trim();
            strOut += string.Format("<tr><td><a href=\"{0}\">{1}</a></td></tr>\n", itemurl, itemname);
        }
        catch { /* do not create markup for this link */ }
    }

     

     

    Technorati tags: , ,
    © 2007 mhinze.com