Read SharePoint list item that includes attachment only using CAML Query

Read SharePoint list item that includes attachment only using CAML Query

Read SharePoint list item that includes attachment only using CAML Query.  In this article, I describe you to Read SharePoint list item that includes attachment only using CAML Query. SharePoint List can contain items as well as attachments in respective items. Let’s assume that we have a scenario to get all those items that include an attachment. Below is code to Read SharePoint list item that includes attachment only using CAML Query.

[AdSense-A]

static void FilterByFileonlyListItem()   Get item that have attahcment only
        {
            using (SPSite _Site = new SPSite(_Url))            {
                using (SPWeb _Web = _Site.OpenWeb())
                {

                    SPList _List = _Web.Lists["Leave"];
                    SPFolder oFolder = _List.RootFolder.SubFolders["Folder_Name"];
                    SPQuery _Query = new SPQuery();
                    _Query.Query = @" <Where>
                                      <Eq>
                                         <FieldRef Name='ID' />
                                         <Value Type='Counter'>1</Value>
                                      </Eq>
                                   </Where>";
                    _Query.RowLimit = 100;
                    _Query.Folder = oFolder;
                    _Query.ViewFields = " <FieldRef Name='Title' /> <FieldRef Name='ID' />";
                    _Query.ViewAttributes = "Scope=\"FilesOnly\"";
                    SPListItemCollection _Items = _List.GetItems(_Query);
                    // System.Data.DataTable _Table = _List.GetItems(_Query).GetDataTable();
                    foreach (SPListItem _Item in _Items)
                    {
                        Console.WriteLine(_Item.ID + " - " + Convert.ToString(_Item["Title"]));
                    }

                }
            }
        }

 


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!