kamagra how much to take

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:

  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:

  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. }
  12. BuildListFiles(web, tempCollection);
  14. return tempCollection;
  15. }
  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!


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>