获取splistitem的附件的URL

Imagine a remote application that uses SharePoint Web Services to retrieve a list item’s attachments to perform some action on them or provide a link to them. This application could have been coded in WSS 2.0 using a mix of the GetListItems and GetAttachmentCollection methods of the Lists Web Service. However, the performance of such an app is extremely poor, since the developer had to issue a GetAttachmentCollection call for each item on the list.

In WSS 3.0, getting the complete list of attachments of each of the items in a list can be accomplished with a single call to GetListItems, using the IncludeAttachmentUrls query parameter, which is new for 3.0. The WSS 3.0 SDK’s GetListItems reference and how-to currently does not provide any documentation for this new parameter, so I hope this blog entry will sufficiently compensate for that in the interim. The way to use the IncludeAttachmentUrls parameter is shown in the following snippet of code:

Web_Reference_Folder_Name.Lists listService = new Web_Reference_Folder_Name.Lists();

listService.Credentials = System.Net.CredentialCache.DefaultCredentials;

 

XmlDocument xmlDoc = new System.Xml.XmlDocument();

XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");

XmlNode ndViewFields = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields",

"");

XmlNode ndQueryOptions = xmlDoc.CreateNode(XmlNodeType.Element,

"QueryOptions", "");

 

ndQueryOptions.InnerXml =

"<IncludeAttachmentUrls>TRUE</IncludeAttachmentUrls>";

ndViewFields.InnerXml = "";

ndQuery.InnerXml = "";

 

try

{

XmlNode ndListItems = listService.GetListItems("List_Name", null,

ndQuery, ndViewFields, null, ndQueryOptions);

      MessageBox.Show(ndListItems.OuterXml);

}

 

catch (System.Web.Services.Protocols.SoapException ex)

{

MessageBox.Show("Message:\n" + ex.Message + "\nDetail:\n" +

ex.Detail.InnerText + "\nStackTrace:\n" + ex.StackTrace);

}

The XML fragment returned will contain the List Item Attachments under the ows_Attachments Field, delimited by ;#. An example of a row of data returned by this method is shown below:

<z:row ows_ID="2" ows_ContentTypeId="0x0104001CAAB92900F22E4CBEF571BC76308DBE" ows_ContentType="Announcement" ows_Title="test" ows_Modified="2007-02-25 14:23:31" ows_Created="2007-02-25 14:21:02" ows_Author="1073741823;#System Account" ows_Editor="1073741823;#System Account" ows_owshiddenversion="3" ows_WorkflowVersion="1" ows__UIVersion="512" ows__UIVersionString="1.0" ows_Attachments=";#http://server/Lists/Announcements/Attachments/2/test.txt;#http://server/Lists/Announcements/Attachments/2/UIP_Setup.log;#" ows__ModerationStatus="0" ows_LinkTitleNoMenu="test" ows_LinkTitle="test" ows_SelectTitle="2" ows_Order="200.000000000000" ows_GUID="{17DD533F-97A2-4DB2-B925-A941D8BFFBD6}" ows_FileRef="2;#Lists/Announcements/2_.000" ows_FileDirRef="2;#Lists/Announcements" ows_Last_x0020_Modified="2;#2007-02-25 14:21:02" ows_Created_x0020_Date="2;#2007-02-25 14:21:02" ows_FSObjType="2;#0" ows_PermMask="0x7fffffffffffffff" ows_FileLeafRef="2;#2_.000" ows_UniqueId="2;#{FA303EDB-4009-4CC5-9EF2-E7402D3BD0C1}" ows_ProgId="2;#" ows_ScopeId="2;#{DEDE57E4-DE8E-4CF9-9BBC-924175CED304}" ows__EditMenuTableStart="2_.000" ows__EditMenuTableEnd="2" ows_LinkFilenameNoMenu="2_.000" ows_LinkFilename="2_.000" ows_ServerUrl="/Lists/Announcements/2_.000" ows_EncodedAbsUrl="http://server/Lists/Announcements/2_.000" ows_BaseName="2_" ows_MetaInfo="2;#" ows__Level="1" ows__IsCurrentVersion="1" ows_Body="<div class="ExternalClass0BA3FF0220C34E74A624A1FC0C7F0DA8"> <div>test</div></div>" />

SDK References

转载于:https://www.cnblogs.com/ahjxxy/archive/2010/12/07/1899523.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值