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 am following this link on how to create metadata navigation :-

http://markuspersson.wordpress.com/2012/01/19/add-metadata-navigation-on-custom-page-layouts/

so I added the references for the navigation , but now I want to know where I should add the following code:-

public class CustomWikiPageBase : PublishingLayoutPage
{
    protected override void OnInit(EventArgs e)
    {
        if (!String.IsNullOrEmpty(Request.QueryString["TreeField"]) 
            && !String.IsNullOrEmpty(Request.QueryString["TreeValue"]))
        {
            Response.Redirect(String.Format("{0}?TreeField={1}&TreeValue={2}",
                SPContext.Current.ListItem.ParentList.DefaultViewUrl,
                Request.QueryString["TreeField"],
                Request.QueryString["TreeValue"]));
        }
        else if (!String.IsNullOrEmpty(Request.QueryString["TreeField"]))
        {
            Response.Redirect(String.Format("{0}?TreeField={1}",
                SPContext.Current.ListItem.ParentList.DefaultViewUrl,
                Request.QueryString["TreeField"]));
        }
        base.OnInit(e);
    }
}

Is there a way to add this code on a web part? If yes then what type of web part it should be ? and could I do this using SharePoint designer?

BR

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You can do this in a regular web part (don't need a visual web part). Just put the OnInit override method in the web part code.

share|improve this answer
    
i tried overriding the Oninit method , but it raised the following error inside Visual Studio :- Error 2 The name 'Request' does not exist in the current context. –  John Peter May 28 '13 at 21:46
1  
You can use HttpContext.Current.Request and HttpContext.Current.Response. –  John Chapman May 29 '13 at 14:08
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.