About      |       Articles      |      Services      |      Software      |      Contact

Latest Free SharePoint Software

ARB Security Solutions regularly releases free SharePoint software, including WebParts, Client Applications, Framework Extensions, and other Miscellaneous Components.
The most recent freeware is:

Title: Simple SharePoint Rollup WebPart
Date Published: 10/22/2009

Previous Two Free WebPart Releases:

SecureCenter For SharePoint

By SharePoint security integrators, for SharePoint security integrators.

SharePoint Security Assurance Program™

For externally facing SharePoint deployments, security is an acutely important deployment concern. Learn how through daily security scanning, you can ensure external business users and partners that they can collaborate in confidence!

Security Assurance WebPart:



Building Master SPFile WebForm Collections, Remember SPListItems!

It is essential to remember when trying to get the entirety of WebForms within a SPWeb object to make certain that you loop through both the SPWeb.Files to compensate for the root level file collection as well as through each SPList testing its items. Often times you will find when trying to build a “master” SPFileCollection there will only be the first condition satisfied.

Essentially you end up with this, which is bad:

C#:
  1. private static SPFileCollection BuildAllFiles(SPWeb web)
  2. {
  3. return web.Files;
  4. }

However this will only return the SPFile objects that are located in the root directory for the SPWeb, negating other WebForms that may exist in other libraries. In order to build all applicable WebForms, instead use a SPFile typed collection for return allocation built by two exclusive methods:

C#:
  1. private static List<SPFile> BuildAllFiles(SPWeb web)
  2. {
  3. List<SPFile> tempCollection = new List<SPFile>();
  4. foreach (SPFile file in web.Files)
  5. {
  6. if(!tempCollection.Contains(file))
  7. {
  8. tempCollection.Add(file);
  9. }
  10. }
  11.  
  12. BuildListFiles(web, tempCollection);
  13.  
  14. return tempCollection;
  15. }
  16.  
  17. private static void BuildListFiles(SPWeb web, ICollection<SPFile> tempCollection)
  18. {
  19. foreach (SPList list in web.Lists)
  20. {
  21. foreach (SPListItem item in list.Items)
  22. {
  23. SPFile file = item.File;
  24. if (file != null && item.File.Url.ToLowerInvariant().EndsWith(".aspx") && !tempCollection.Contains(file))
  25. {
  26. tempCollection.Add(file);
  27. }
  28. }
  29. }
  30. }

You can see in the above, contrasting a singular SPFileCollection return, we are looping through that collection in the beginning and adding the SPFile objects to the typed collection. With the second method call, we are going through every SPList object on the SPWeb and getting the file representation of each SPListItem. After we have the file representation, we test whether this property is null, whether it ends with an .aspx suffix (since we are inspecting for WebForms), and then adding that SPFile to the collection if it is not present. We end up with a “master” SPFile collection that we can start performing whatever operations we like on!

  • Share/Bookmark

1 Comment »

  1. Nice blog !

    Good job, Thanks for the information

    Comment by Anonymous — December 25, 2008 @ 1:05 am

RSS feed for comments on this post. TrackBack URL

Leave a comment