Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have created a custom webpart.

I want to get that webpart and add it to my custom application page using code. How can I get it?

share|improve this question
    
What do you mean by get it? Do you want to use it in the application page code? –  user3470 Nov 6 '12 at 9:27
    
Yes, I want to add that custom webpart in my Application page using code.. –  Torque Nov 6 '12 at 10:16
add comment

1 Answer 1

up vote 2 down vote accepted

You can get all the Web Parts on a specific site by accessing the Web Part Gallery List.
For example:

SPWeb web = SPContext.Current.Web;
SPList list = web.Lists["Web Part Gallery"];
foreach(SPListItem item in list.Items)
{
  // do something
}
share|improve this answer
    
Thanx Moussa, It worked for me. So it means all the webparts are stored in a List/Library.. I was struggling for last 5-7 hours to get webpart from site. –  Torque Nov 6 '12 at 10:40
add comment

Your Answer

 
discard

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.