duke008

导航

获取SPListItem对象所在的SPFolder

 

        /// <summary>
        /// 获取SPListItem对象所在的SPFolder
        /// </summary>
        /// <param name="item">SPListItem对象</param>
        /// <returns>SPListItem对象所在的SPFolder</returns>
        public static  SPFolder GetItemsFolder(SPListItem item)
        {
            string dirPath = SPUtility.GetUrlDirectory(item.Url);

            SPList list = item.ParentList;

             if(list.ParentWeb.ServerRelativeUrl!="/")

            dirPath=string.Format("{0}/{1}",list.ParentWeb.ServerRelativeUrl,dirPath);
            SPListItem folderItem = list.ParentWeb.GetListItem(dirPath);
            if (folderItem != null)
                return folderItem.Folder;
            else
                return null;
        }
 

posted on 2009-04-18 12:06  Pegasus  阅读(730)  评论(1编辑  收藏  举报