---
title: "如何取到MOSS列表中item的链接"
author: "carysun"
date: "2008-12-04T18:07:00Z"
tags: []
slug: "moss-item"
draft: false
lastmod: "2008-12-04T18:07:00Z"
id: 463240
url: "https://carysun.iteye.com/blog/463240"
---

SPListItem的Url属性返回的不是绝对路径，形式如下面：  
[http://cary/Lists/Discussion/itemtitle](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](http://cary/Lists/Discussion/DispForm.aspx?ID=680)  
这个就可以作为链接打开了.