Since it inherits from SPList and the only way I know to create a SPDocumentLibrary is to convert it from an SPList object using:

SPDocumentLibrary lib = (SPDocumentLibrary)list;

Why would anyone use an SPDocumentLibrary until the very last moment when they absolutely needed the member of that class?

It just seems like an extra unneeded step to convert to a SPDocumentLibrary unless you specifically need to access one of its members, most of which are already part of the SPList class. Maybe I am missing something, but I frequently see people doing this conversion, then never using any specific to the SPDocumentLibrary class

1 Answer 1


You should only do the cast if you need the extra functionality.

But note that it's not a convertion it's only a cast. The list in you example is already a SPDocumentLibrary we're just telling the compiler that this is the case.

Yes, it'll add a check to verify our claim, but there is no noticable performance penalty in this.
The main disadvantage of making the cast is that your code will not work unless the list is a document library, which will make it less reusable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.