0

is it possible to use Client Object Model in the application page (say in the head tag) present under layouts folder(example:xlviewer.aspx)?, to fetch the current logged-in username. OR do we have to create new application page via visual studio and deploy it?

variable
  • 4,473
  • 13
  • 75
  • 139

1 Answers1

1

Of course it is. But why do you want to use the Client Object Model? Also, don't overwrite or change any of the oob SharePoint pages in the Layouts folder.Just create your own and deploy it via a Solution.

The code you can use is :

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        lblUserName.Text = SPContext.Current.Web.CurrentUser.LoginName;
    }
}

If you really need to use Client Object Model, read here: Get current user in Client Object Model with javascript?

Fox
  • 2,676
  • 1
  • 18
  • 30
  • Can I create a copy of the aspx page and use it? Would that be safe? – variable Feb 04 '14 at 07:20
  • No, you can't copy an aspx page. The page itself references a Type. Copying the page will reference the same type. – Fox Feb 04 '14 at 07:37
  • You mean to say it will reference to the same code behind. So then I can use a custom IHttpRedirector, check if the page is say page1.aspx then redirect to page2.aspx; where page2 is copy of page1 isnt it? – variable Feb 04 '14 at 07:39
  • Indeed, it will reference the same codebehind (Type or class). Doing that would be so much work. Why not just create your own page.. If you don't need code behind (C#), just leave the codebehind property empty.. – Fox Feb 04 '14 at 07:43
  • OK, if I create a new application page, then also I believe will have to use redirector so that sharepoint will redirect the user from the default apppage to the custom one I created. Isnt it? – variable Feb 04 '14 at 08:17
  • Where are you planning to redirect the user from? Is it a link somewhere in a built in SharePoint page? – Fox Feb 04 '14 at 08:24
  • Say for example the layouts\xlviewer.aspx page which opens when you open an excel book from doc library.. – variable Feb 04 '14 at 08:28
  • You have two options:
    1. Use a SharePoint CustomAction to hide the out of the box option to edit the excel file and create a new CustomAction to go to your custom aspx Page.
    2. Use a HttpModule (Such as the redirector) to redirect requests for xlviewer.aspx to mycustomxlviewer.aspx
    – Fox Feb 04 '14 at 08:38