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 SharePoint View Queries with CAML

Often times when building applications that will greatly use SharePoint views for data rotation it is helpful to build CAML builders into separate static classes that return a continuous string representation of the arbitrary query. In order to demonstrate this, consider the following examples BuildDefaultViewQuery, BuildPrivateViewQuery, and BuildPublicViewQuery:

C#:
  1. private static string BuildDefaultViewQuery()
  2. {
  3. var builder = new StringBuilder();
  4. builder.Append("<Where>");
  5. builder.Append("<Eq><FieldRef Name='DefaultView' /><Value Type='Boolean'>");
  6. builder.Append("1");
  7. builder.Append("</Value></Eq></Where>");
  8. return builder.ToString();
  9. }
  10.  
  11. private static string BuildPrivateViewQuery(string user)
  12. {
  13. var builder = new StringBuilder();
  14. builder.Append("<OrderBy><FieldRef Name='ViewName'/> </OrderBy>");
  15. builder.Append("<Where><Eq><FieldRef Name='ViewCreator' /><Value Type='Text'>");
  16. builder.Append(user);
  17. builder.Append("</Value></Eq></Where>");
  18. return builder.ToString();
  19. }
  20.  
  21. private static string BuildPublicViewQuery(string user)
  22. {
  23. var builder = new StringBuilder();
  24. builder.Append("<OrderBy><FieldRef Name='Audience'/> <FieldRef Name='ViewName'/></OrderBy>");
  25. builder.Append("<Where><Or><Eq><FieldRef Name='ViewCreator' /><Value Type='Text'>");
  26. builder.Append(user);
  27. builder.Append("</Value></Eq>");
  28. builder.Append("<Eq><FieldRef Name='Audience' /><Value Type='Choice'>");
  29. builder.Append("1");
  30. builder.Append("</Value></Eq></Or></Where>");
  31. return builder.ToString();
  32. }

It should be noted that there are some constants that could instead be extracted to an enumeration and then Enum.GetName could be used for better component allocation. However, in this example since it is merely to show the overlying constructs, is kept purposefully plain.

In order to use one of static CAML methods, the ReturnCollectionExample method will take some basic parameters, than return the item collection associated with the BuildPrivateViewQuery query.

C#:
  1. private static SPListItemCollection (string url, string viewName, string userId)
  2. {
  3. using (var site = new SPSite(url))
  4. {
  5. using (SPWeb web = site.OpenWeb())
  6. {
  7. var query = new SPQuery { Query = BuildPrivateViewQuery(userId) };
  8. return web.Lists[viewName].GetItems(query);
  9. }
  10. }
  11. }

  • Share/Bookmark

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment