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:



Casting To SPDocumentLibrary

A friend just asked me the way to cast a SPList To a SPDocumentLibrary so that he could access the document library specific attributes for document library objects. This is one way of doing it:

C#:
  1. public static SPWeb GetWeb(string url)
  2. {
  3. using (SPSite site = new SPSite(url))
  4. {
  5. using (SPWeb web = site.OpenWeb())
  6. {
  7. return web;
  8. }
  9. }
  10. }
  11.  
  12. public static SPDocumentLibrary CastDocumentLibrary(string url, string libraryName)
  13. {
  14. return GetWeb(url).Lists[libraryName] as SPDocumentLibrary;
  15. }

Obviously, the casting can take on many forms, but the end result is still an SPDocumentLibrary object.

  • Share/Bookmark

3 Comments »

  1. Isn’t GetWeb() returning a reference to a disposed object?

    Comment by Viktor Dolezel — November 19, 2008 @ 8:49 am

  2. The expression in the return statement is evaluated before the object is disposed.

    Comment by Adam Buenz — November 19, 2008 @ 9:14 am

  3. I believe Viktor is correct. GetWeb disassembled looks like this:

    public static SPWeb GetWeb(string url)
    {
    SPWeb temp;
    using (SPSite site = new SPSite(url))
    {
    using (SPWeb web = site.OpenWeb())
    {
    temp = web;
    }
    }
    return temp;
    }

    Comment by Keith Dahlby — January 18, 2009 @ 4:06 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment