Display Dynamic Web app in O365

73 views Asked by At


I am trying to convert a current web part we use in SharePoint 2012 to an App that will be displayed on every users homepage When they go to our O365 site. Its a simple App all it does is display if the user has completed their time sheet (based on who you are from AD). But its not an App anyone will "Click" on.

I have seen articles say cut code from Iframe generated by the App and place that code on the page. I don't think this will work as I need to pass it the user and display only their data.

I Appreciate any thoughts on the best way to do this. If the Iframe is usable, I'd take thoughts on how to get it the user I am getting from O365 passed to it.

Thanks In Advance

Steve Zelonis

2

There are 2 answers

0
Mostafa On

If you created a SharePoint provider hosted app, below code you can insert it in the Index controller to pull the user info.

User spUser = null;

        var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);

        using (var clientContext = spContext.CreateUserClientContextForSPHost())
        {
            if (clientContext != null)
            {
                spUser = clientContext.Web.CurrentUser;

                clientContext.Load(spUser, user => user.Title);

                clientContext.ExecuteQuery();

                ViewBag.UserName = spUser.Title;
            }
        }

Hope this helps.

2
Mostafa On

You don't need to use iFrames, You can create a SharePoint App and embed your logic in it, when you are done, you can deploy it to SP in o365.

You can use SharePoint Provider or Provider Hosted based on the preferred hosting environment for your app either SP or Azure.

Hope this helps.