0

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

1

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.

2
  • 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. May 29 '13 at 14:08

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.