Search for all documents in a site that end with a specific extention using Sharepoint 2010 Client Object Model

StackOverflow https://stackoverflow.com/questions/7349748

Question

I'm absolutely new to Sharepoint programming, so I need a bit of guidance on how to get a list of all documents that exist within a Sharepoint site who's extension matches a value being passed in.


Background: As part of a merger, millions (7TB) of documents were imported into Sharepoint without regard to file type, simply so we could get that data stored from a system that was being shut down.

Included in these documents were dangerous file types like .exe, and .dll files, which we need to preserve but want to take proper steps to ensure malicious files of those types aren't directly down-loadable.

Our plan is to extract each file matching our search list, zip it, upload the zip and delete the original. To do this, we need a one shot application.

There are actually multiple sites involved - so ideally I'd love to run one query to access all documents in all sites (they're all under one root but they each have their own databases) but I'm fine with iterating across a set of sites.


My thinking is to use the Sharepoint Client Object Model to execute a query against each site to give me back a list of all files of a given type. I want something like

SharepointSite site = new SharepointSite(siteElement, settings.RootURL);
ClientContext clientContext = site.Context;
ListCollection listCollection = clientContext.Web.Lists;
clientContext.Load(listCollection, l=>l.Name.EndsWith(".exe"));
clientContext.Load(listCollection);
clientContext.ExecuteQuery();

but that's definitely not it.

How should I approach this issue?

Was it helpful?

Solution 2

In the end, I created a direct query against the database to get a specific list of all matching documents w/o iterating over millions of items, and then was able to use the client components to pull the exact file I wanted.

OTHER TIPS

Start with basic coding in Client object model. You just need to iterate over sites, its lists and then its contents.

http://msdn.microsoft.com/en-us/library/ee857094.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top