首页 > 其他专区 > SharePoint >

moss 2010 如何取到MOSS列表中item的链接

SharePoint 2021-09-23 11:08:34

SPListItem的Url属性返回的不是绝对路径,形式如下面:
http://cary/Lists/Discussion/itemtitle
这种形式是不能作为链接打开的,很多时候我们在取到这个item的同时还要得到这个item的url,比如你筛选出列表中指定的数据并发邮件给相关人员的时候,在邮件的内容中就需要有个这个item的链接。

Moss中提供了一个PAGETYPE枚举,具体如下表:

名称  描述
 PAGE_DEFAULTVIEW  Default view. Value=0.
 PAGE_DIALOGVIEW  File dialog box view. Value=2.
 PAGE_DISPLAYFORM  Display form for list items. Value=4.
 PAGE_DISPLAYFORMDIALOG  Display form for a file dialog box. Value=5.
 PAGE_EDITFORM  Edit form for list items. Value=6.
 PAGE_EDITFORMDIALOG  Edit form for a file dialog box. Value=7.
 PAGE_INVALID  Not used. Value= -1.
 PAGE_MAXITEMS  Not used. Value=11.
 PAGE_NEWFORM  New form for list items. Value=8.
 PAGE_NEWFORMDIALOG  New form for a file dialog box. Value=9.
 PAGE_NORMALVIEW  Normal view. Value=1.
 PAGE_SOLUTIONFORM  Solution form. Value=10.
 PAGE_VIEW  View, including both default view and normal view. Value=3.

我们就可以通过如下代码来得到item的链接:
SPList list = site.Lists.GetList("/Lists/Discussion ");
SPListItem item = list.Items[id];
String strUrl=list.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url + "?ID=" + item.ID

利用这个可以得到下面形式链接:
http://cary/Lists/Discussion/DispForm.aspx?ID=680
这个就可以作为链接打开了.

 

附录:

            DataTable dt = new DataTable();
            dt.Columns.Add("标题");
            dt.Columns.Add("路径");
           
            SPSite site = new SPSite("http://sharepoint02:9003");
            SPWeb web = site.OpenWeb();
            SPList list = web.GetList("/Lists/List1");
            String strUrl = "";
            for (int i = 0; i < list.Items.Count; i++)
            {
                strUrl = list.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url + "?ID=" + list.Items[i].ID;
                DataRow dr = dt.NewRow();
                dr["标题"] = list.Items[i].Title;
                dr["路径"] = "" + list.Items[i].Title + "";
                dt.Rows.Add(dr);
            }


标签: moss2010如何表中item

office教程网 Copyright © 2016-2020 https://www.office9.cn. Some Rights Reserved.