Query Options的一些用法(2): 包含附件路径

 

接着上一篇:Query Options的一些用法(1): 展开用户列信息

这次增加了两条新的列表记录。第二条没有附件,第三条有2个附件,并且给第一条记录增加了一个附件。

Query Options的一些用法(2): 包含附件路径

View fields增加附件的引用。这样可以显示附件信息。

static XmlNode ViewFields

{

get

{

XmlElement viewFields = _camlDoc.CreateElement("ViewFields");

System.Text.StringBuilder viewFieldsSB = new System.Text.StringBuilder();

#region View Fields

viewFieldsSB.Append(" <FieldRef Name=\"Title\" />");

viewFieldsSB.Append(" <FieldRef Name=\"Attachments\" />");

viewFieldsSB.Append(" <FieldRef Name=\"Author\" />");

viewFieldsSB.Append(" <FieldRef Name=\"Editor\" />");

#endregion

string sResult = viewFieldsSB.ToString();

viewFields.InnerXml = viewFieldsSB.ToString();

return viewFields;

}

}

运行一个不包含任何Query Options的查询。

得到如下结果,包含附件的记录显示1,不包含显示0,即使包含多个附件,也只显示1,这个值更像表示当前的记录是否包含附件。

<rs:data ItemCount="3" xmlns:rs="urn:schemas-microsoft-com:rowset">

<z:row ows_Title="Test01" ows_Attachments="1" ows_Author="1;#Qin, Lei (Lambert, ES-Apps-GD-China-SH)" ows_Editor="1;#Qin, Lei (Lambert, ES-Apps-GD-China-SH)" ows_MetaInfo="1;#" ows__ModerationStatus="0" ows__Level="1" ows_ID="1" ows_UniqueId="1;#{E1F2046C-16AC-4650-8EE3-73E12ED5E833}" ows_owshiddenversion="2" ows_FSObjType="1;#0" ows_Created="2012-11-30 01:37:17" ows_PermMask="0x7fffffffffffffff" ows_Modified="2012-11-30 02:43:10" ows_FileRef="1;#teams/smetechcom/Lists/QueryOptionsDemo/1_.000" xmlns:z="#RowsetSchema" />

<z:row ows_Title="Test02" ows_Attachments="0" ows_Author="1;#Qin, Lei (Lambert, ES-Apps-GD-China-SH)" ows_Editor="1;#Qin, Lei (Lambert, ES-Apps-GD-China-SH)" ows_MetaInfo="2;#" ows__ModerationStatus="0" ows__Level="1" ows_ID="2" ows_UniqueId="2;#{DCDE833B-E69A-4C63-B9FE-0AE5938B3CDE}" ows_owshiddenversion="1" ows_FSObjType="2;#0" ows_Created="2012-11-30 02:48:12" ows_PermMask="0x7fffffffffffffff" ows_Modified="2012-11-30 02:48:12" ows_FileRef="2;#teams/smetechcom/Lists/QueryOptionsDemo/2_.000" xmlns:z="#RowsetSchema" />

<z:row ows_Title="Test03" ows_Attachments="1" ows_Author="1;#Qin, Lei (Lambert, ES-Apps-GD-China-SH)" ows_Editor="1;#Qin, Lei (Lambert, ES-Apps-GD-China-SH)" ows_MetaInfo="3;#" ows__ModerationStatus="0" ows__Level="1" ows_ID="3" ows_UniqueId="3;#{74218240-4455-4FCA-AE83-5B966DF6F484}" ows_owshiddenversion="2" ows_FSObjType="3;#0" ows_Created="2012-11-30 03:04:00" ows_PermMask="0x7fffffffffffffff" ows_Modified="2012-11-30 03:04:45" ows_FileRef="3;#teams/smetechcom/Lists/QueryOptionsDemo/3_.000" xmlns:z="#RowsetSchema" />

</rs:data>

 

如果需要知道附件的URL呢?

一种方式是,使用Lists.GetAttachmentCollection方法,通过传入列表名和列表记录ID来查询。

另外也就是可以指定Query Options:IncludeAttachmentUrls来进行查询了。

修改Query Options包含附件。

static XmlNode QueryOptions

{

get

{

 

XmlElement queryOptions = _camlDoc.CreateElement("QueryOptions");

queryOptions.InnerXml = "<IncludeAttachmentUrls>True</IncludeAttachmentUrls>";

return queryOptions;

}

}

运行一下,可以发现,如果没有附件,结果仍然是0。如果有附件,附件完整的URL就会显示出来了。首尾都有一个;#,多个附件以分隔;#

<rs:data ItemCount="3" xmlns:rs="urn:schemas-microsoft-com:rowset">

<z:row ows_Title="Test01" ows_Attachments=";#http://ent191.sharepoint.hp.com/teams/smetechcom/Lists/QueryOptionsDemo/Attachments/1/test.xlsx;#" ows_Author="1;#Qin, Lei (Lambert, ES-Apps-GD-China-SH)" ows_Editor="1;#Qin, Lei (Lambert, ES-Apps-GD-China-SH)" ows_MetaInfo="1;#" ows__ModerationStatus="0" ows__Level="1" ows_ID="1" ows_UniqueId="1;#{E1F2046C-16AC-4650-8EE3-73E12ED5E833}" ows_owshiddenversion="2" ows_FSObjType="1;#0" ows_Created="2012-11-30 01:37:17" ows_PermMask="0x7fffffffffffffff" ows_Modified="2012-11-30 02:43:10" ows_FileRef="1;#teams/smetechcom/Lists/QueryOptionsDemo/1_.000" xmlns:z="#RowsetSchema" />

<z:row ows_Title="Test02" ows_Attachments="0" ows_Author="1;#Qin, Lei (Lambert, ES-Apps-GD-China-SH)" ows_Editor="1;#Qin, Lei (Lambert, ES-Apps-GD-China-SH)" ows_MetaInfo="2;#" ows__ModerationStatus="0" ows__Level="1" ows_ID="2" ows_UniqueId="2;#{DCDE833B-E69A-4C63-B9FE-0AE5938B3CDE}" ows_owshiddenversion="1" ows_FSObjType="2;#0" ows_Created="2012-11-30 02:48:12" ows_PermMask="0x7fffffffffffffff" ows_Modified="2012-11-30 02:48:12" ows_FileRef="2;#teams/smetechcom/Lists/QueryOptionsDemo/2_.000" xmlns:z="#RowsetSchema" />

<z:row ows_Title="Test03" ows_Attachments=";#http://ent191.sharepoint.hp.com/teams/smetechcom/Lists/QueryOptionsDemo/Attachments/3/test.xlsx;#http://ent191.sharepoint.hp.com/teams/smetechcom/Lists/QueryOptionsDemo/Attachments/3/test1.xlsx;#" ows_Author="1;#Qin, Lei (Lambert, ES-Apps-GD-China-SH)" ows_Editor="1;#Qin, Lei (Lambert, ES-Apps-GD-China-SH)" ows_MetaInfo="3;#" ows__ModerationStatus="0" ows__Level="1" ows_ID="3" ows_UniqueId="3;#{74218240-4455-4FCA-AE83-5B966DF6F484}" ows_owshiddenversion="2" ows_FSObjType="3;#0" ows_Created="2012-11-30 03:04:00" ows_PermMask="0x7fffffffffffffff" ows_Modified="2012-11-30 03:04:45" ows_FileRef="3;#teams/smetechcom/Lists/QueryOptionsDemo/3_.000" xmlns:z="#RowsetSchema" />

</rs:data>

你可能感兴趣的:(option)