SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a web part that need to have its own document library. Is there any way for me to check to see if that document library exists and if not create it, when the WSP is installed?

share|improve this question
up vote 3 down vote accepted

Yes, you would do this via a Feature Receiver for the Feature that deploys the web part.

For more information on creating a Feature Receiver see:

Here's a simple example that shows how to create a document library in code:

share|improve this answer
I tried to add this to the FeatureActivated event but it says SPContext.Current.Site is null. Should i be doing this somewhere else? – Abe Miessler May 7 '11 at 15:47
Nevermind, I found a solution for that here:… – Abe Miessler May 7 '11 at 15:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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