SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hi I'm trying to get file from a documentLibray with LINQ Query. I've been trying with this code but I get nothing!

 var allegatiCollegati = (from SPFile attach in web.Lists.["Allegati"].items

                         select attach ).ToList();
share|improve this question

SPList.Items (web.Lists.["Allegati"].Items) returns an SPListItemCollection collection, which contains SPListItem and not SPFile objects. You can get the SPFile from the SPListItem by calling SPListItem.File.

share|improve this answer
var files = web.Lists["Allegati"].items
.Cast<SPListItem>()
.Where(item=>item.File!=null)
.Select(item=>item.File)
.ToList();
share|improve this answer
    
Remove dot between Lists and ["Allegati"] – Louis Apr 26 '12 at 1:54
    
removed, thanks to point out~ – Eric Apr 26 '12 at 7:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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