0

We are creating Linq to Sharepoint entities using SPMetal.exe for a site.

We got the entities.cs file created by SPMetal.exe successfully.

We have a document library inside the site say (doclibrary1). There we will be having folders,sub-folders and document set inside the sub-folders. I am defining a custom content type say (contype1) and assigned it as the default content type for the document library. Now how to query for all the document set from the document library entity produced in entities.cs. Can anybody help in achieving my objective through Linq ?.

I had tried the following links

http://rgielen.blogspot.com/2010/10/spmetal-linq-to-sharepoint-2010.html

http://collab.rdacorp.com/2010/05/linq-to-sharepoint-and-document-sets.html

code snippets,illustrated examples and useful links are really appreciated.

Thanks

1

I don't use SPMetal against a Document Library, but I do against a Photo Gallery. The following seems to work for me. Hopefully this can help get you started. This should return a list of the items within a given folder in a photo gallery.

SPMetal XML:

<?xml version="1.0" encoding="utf-8"?>
<Web AccessModifier="Public" Class="PhotoGalleryDao" xmlns="http://schemas.microsoft.com/SharePoint/2009/spmetal">
  <List Name="Photo Gallery" Type="PhotoGalleryItem">
    <ContentType Name="Picture" Class="PhotoGalleryItem">
        <IncludeHiddenColumns/>
    </ContentType>
  </List>
  <ExcludeOtherLists/>
  <ExcludeOtherContentTypes/>
</Web>

Provider:

using SPLinq.PhotoGalleryDao;

namespace PhotoGallery.Providers
{
    public static class PhotoGalleryDataProvider
    {

        public static List<PhotoGalleryItem> GetPhotoGalleryItems(string folderName)
        {
            using (PhotoGalleryDao _dao = new PhotoGalleryDao(SPContext.Current.Web.Site.RootWeb.Url.ToString()))
            {
                IEnumerable<PhotoGalleryItem> result = (from p in _dao.PhotoGallery.ScopeToFolder(folderName, true)
                                                        orderby p.Name
                                                        select p);
                List<PhotoGalleryItem> resultsList = result.ToList();
                return resultsList;
            }
        }

    }
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.