如何从SPListItem(curren项目)获取完整URL?

时间:2013-04-19 21:21:09

标签: jquery sharepoint-2010 spservices

这是我的代码,但我不知道哪个是url的字段。我可以用不同的方式获取网址吗?

var f = "<ViewFields>"+
                '<FieldRef Name="Title"/>'+
                '<FieldRef Name="LinkFilenameNoMenu"/>'+
                '<FieldRef Name="Created"/>'+
            "</ViewFields>";

1 个答案:

答案 0 :(得分:3)

这很容易,但很难找到。

var f = "<ViewFields>"+
                '<FieldRef Name="ID"/>'+
                '<FieldRef Name="Title"/>'+
                '<FieldRef Name="LinkFilenameNoMenu"/>'+
                '<FieldRef Name="Created"/>'+
                '<FieldRef Name="EncodedAbsUrl"/>'+
            "</ViewFields>";
$().SPServices({
operation: "GetListItems",
async: false,
listName: list,
CAMLViewFields: f,
CAMLLimit: l,
CAMLQuery: q, 



completefunc: function (xData, Status) {

  $(xData.responseXML).SPFilterNode("z:row").each(function() {



      var url = $(this).attr("ows_EncodedAbsUrl")

    });
  }
});

它适用于C#代码,您可以使用ows_EncodedAbsUrl元数据值:

using (SPSite site = new SPSite(webUrl))
{
   using (SPWeb web = site.OpenWeb())
   {
       SPList list = web.Lists["Shared Documents"];
       SPListItem item = list.Items[0];
       string itemUrl = item["ows_EncodedAbsUrl"].ToString();
   }
}