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.


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 : http://sharepoint.microsoft.com/en-us/resources/Pages/Developer-Training-Guide.aspx

| 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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