Next to the previous article: usage of query options (1): Expand user column information.
Two new list records are added this time. Article 2 has no attachment, article 3 has two attachments, and adds an attachment to the first record.
InView fieldsAdd attachment references. In this way, the attachment information is displayed.
Static XmlnodeViewfields
{
Get
{
XmlelementViewfields = _ camldoc. createelement ("Viewfields");
System. Text.StringbuilderViewfieldssb =NewSystem. Text.Stringbuilder();
# RegionView fields
Viewfieldssb. append ("<Fieldref name = \" title \ "/>");
Viewfieldssb. append ("<Fieldref name = \" Attachments \ "/>");
Viewfieldssb. append ("<Fieldref name = \" author \ "/>");
Viewfieldssb. append ("<Fieldref name = \" editor \ "/>");
# Endregion
StringSresult = viewfieldssb. tostring ();
Viewfields. innerxml = viewfieldssb. tostring ();
ReturnViewfields;
}
}
Run a query that does not contain any query options.
The following result is displayed: 1 is displayed for records containing attachments, and 0 is not displayed. Even if multiple attachments are contained, only 1 is displayed. The value is more like whether the current record contains attachments.
<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 =" 01:37:17 "ows_permmask =" required "ows_modified =" 02:43:10 "ows_fileref =" 1; # teams/smetechcom/lists/queryoptionsdemo/maid "xmlns: z =" # rowsetschema "/>
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 =" 02:48:12 "ows_permmask =" required "ows_modified =" 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; # {authorization} "ows_owshiddenversion =" 2 "ows_fsobjtype =" 3; #0 "ows_created =" 03:04:00 "ows_permmask =" Authorization "ows_modified =" 03:04:45 "ows_fileref =" 3; # teams/smetechcom/lists/queryoptionsdemo/3_.000 "xmlns: z =" # rowsetschema "/>
</RS: DATA>
What if you need to know the URL of the attachment?
One way is to useLists. getattachmentcollectionMethod. You can specify a list name and a list record ID.
In addition, you can specify query options: includeattachmenturls to query.
Modify query options to include attachments.
Static XmlnodeQueryoptions
{
Get
{
XmlelementQueryoptions = _ camldoc. createelement ("Queryoptions");
Queryoptions. innerxml ="<Includeattachmenturls> true </includeattachmenturls>";
ReturnQueryoptions;
}
}
Run the command. If no attachment is available, the result is still 0. If an attachment exists, the complete URL of the attachment is displayed. There is;#Multiple attachments are separated;#.
<RS: Data itemcount = "3" xmlns: rs = "urn: Schemas-Microsoft-com: rowset">
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 =" 01:37:17 "ows_permmask =" required "ows_modified =" 02:43:10 "ows_fileref =" 1; # teams/smetechcom/lists/queryoptionsdemo/maid "xmlns: z =" # rowsetschema "/>
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 =" 02:48:12 "ows_permmask =" required "ows_modified =" 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; # {authorization} "ows_owshiddenversion =" 2 "ows_fsobjtype =" 3; #0 "ows_created =" 03:04:00 "ows_permmask =" Authorization "ows_modified =" 03:04:45 "ows_fileref =" 3; # teams/smetechcom/lists/queryoptionsdemo/3_.000 "xmlns: z =" # rowsetschema "/>
</RS: DATA>