8

I have created a server control and want to place it in the person.aspx page on the My Site however do not want to edit the page through SharePoint Designer but want to edit the file itself from the file system (on the WFE). Where can i find the person.aspx on the WFE?

Update

Now, I understand that we should not edit the SharePoint default pages. So I would like to insert my server control into the person.aspx page without really editing the file itself.

As of now, I have updated the person.aspx (from the site definition) page with the below entries

<% Register TagPrefix="my" Namespace="myControl.demo.Controls" 
Assembly="myControl.demo.Controls, Version=1.0.0.0, Culture=neutral, 
PublicKeyToken=4b179e608e5a0adf" %>

and added the below entry under the "PlaceHolderMain" section:

<my:MyControl ID="MyControl" runat="server"
LabeltoPropertyPair="Some Value :$Value to replace: ,"/>

however would like to do the same without really editing the page itself? How it can be achieved? should I need to use Feature stapling (I do not have any knowledge)?

  • Can you provide some more info? What SharePoint version? Where exactly should your custom WebControl be placed? – Sig Weber Aug 18 '11 at 7:22
  • I found the file "person.aspx" located under the folder - C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\SiteTemplates\SPSMSITEHOST". Basically, My server control is a dll and placed in the GAC. – Karthikeyan Aug 18 '11 at 11:59
  • I meant where your control should appear on the person.aspx page ;-) – Sig Weber Aug 18 '11 at 12:55
7

You should not edit the person.aspx in the file system (updates will likely overwrite it).

SharePoint Designer is the first option, but not a good one. It will customize the page and you will not benefit from pre-compilation, and can cause headaches when upgrading!

One approach that I've previously uses is to add a new feature that puts a control in the AdditionalPageHeaders delegate control. This control is present on all pages. In that control I check the name/url of the page. In this case if it finds person.aspx then redirect to your custom page (custom-person.aspx). The custom page is the modified person.aspx page deployed to the _layouts folder.

1

Another option is to create your own version of person.aspx and include it in a deployable feature that deploys the file to the rootfolder of the rootweb of the MySiteHost. Then, inside a feature receiver, get a reference to the newly deployed file using the SPWeb.Files collection and perform a "MoveTo" operation on it - over the original person.aspx.

Here are a couple methods for applying a custom file to the rootweb, and reverting back. These methods depend on renaming the original file to something else in order to revert back if needed:

  private void ApplyCustomRootFile(string originalFilename, string newFileName, string newNameForOriginalFile)
    {
        SPFileCollection files = Site.RootWeb.Files;
        SPFile originalFile = files[originalFilename];
        originalFile.CopyTo(newNameForOriginalFile, false);

        SPFile newDefaultFile = files[newFileName];
        newDefaultFile.MoveTo(originalFilename, true);
    }
    private void RevertCustomRootFile(string originalFilename, string newNameForOriginalFile)
    {
        SPFileCollection files = Site.RootWeb.Files;
        SPFile originalFile = files[newNameForOriginalFile];
        originalFile.MoveTo(originalFilename, true);
    }

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.