In this article I am just going to explain how to create a reference webpart programmatically.

Requirement:

Need
a webpart that display all pages title with link. Only related page
should display in the link. Webpart should be added in all pages. Same
page should not have hyperlink. In other words the query will return the
page where the webpart is present. But it should have Hyperlink only
with other pages.