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

When creating SharePoint WebParts what is the proper way to go about accessing common methods. For example when developing in .net webforms you can add a .cs file to the App_Code folder and consume classes and methods from that file.

I want to be able to create common code that is shared among all my SharePoint WebParts.

Any ideas? Perhaps I am going about this totally wrong.

share|improve this question

migrated from Mar 23 '12 at 20:06

This question came from our site for professional and enthusiast programmers.

You'll need to create a class library, and place your code in there. You can then deploy this library to your sharepoint farm as part of a solution (.wsp file).

You can create .wsp files in a number of ways. The optimal method depends on your version of SharePoint.

If you are using SharePoint 2010, just create a SharePoint project in Visual Studio and add your code to the project. VS will build the .wsp file for you for deployment.

Here's a good getting started guide for SharePoint 2010 development :

share|improve this answer
So what you are saying is that if I create a .cs file within a .wsp solution and deploy it to my SharePoint Farm it's namespace will then be available in all future .wsp files? – Steve Andekian Mar 26 '12 at 16:32
A .wsp package is just a deployment vessel. Your code will get compiled into a .dll and deployed to the GAC on the target machines (or the BIN directory, if you choose). At that point, you can reference the assembly like you normally would. – Kyle Trauberman Mar 26 '12 at 16:50
If you are planning for a shared library, I would put it in it's own solution (.sln and .wsp). That will allow you to manage deployments better. – Louis Apr 24 '12 at 1:13

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.