Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
add comment

2 Answers 2

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
add comment
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
add comment

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.