SP2013: SharePoint hosted app, getting to your lists
As described in my previous post, a SharePoint app gets its own Web instance in which it lives. For the SharePoint engine, that means getting rid of your app is easy: just delete the web and everything is gone. The web gives you the option to deploy regular SharePoint stuff like lists and columns. But now that you’ve got your solution setup with a list; how can you reach it to add items?
I’m not sure yet how Microsoft wants us to work with this model. It’s not that easy to get to your lists, not for an end user anyway. And since your app uses it’s own interface, the end-user experience is kind of odd when you switch back and forth between SharePoint UI and your apps’ UI.
What you could do is provide a modal dialog (like the ones in SharePoint, which you can’t use in your hosted app because you’re not in SharePoint…) which loads a form. But you’ll need the URL of the form, so here’s how you get there:
- Open your app and copy the URL it presents, it’ll look something like https://localhost:44306/Pages/Default.aspx?SPHostUrl=https://user.sharepoint.com&SPLanguage=en-US&SPAppWebUrl=https://user-703ae13727445b.sharepoint.com/TheaterCompany
- The SPAppWebUrl query string parameter contains the URL of the web where your sites lives. Run the value through a URL decoder (http://meyerweb.com/eric/tools/dencoder/)
- Find the relative URL of your list (in my case: Lists/CharactersInHamlet)
- Append that to your web URL so you end up with something like https://user-703ae13727445b.sharepoint.com/TheaterCompany/Lists/CharactersInHamlet
So now that you can open up your list, you can click the “add new item” link, that’ll take you to the NewForm.aspx page of your list. And if you want to use that in a modal dialog, thus without all the masterpage stuff around the form, add &IsDlg=1 to the URL to strip the page from all unwanted bits.
That way you can reuse the SharePoint form so you don’t have to create one yourself. And since SharePoint also does some validation and stuff, that saves more work.
If you want to provide your form in a completely different way, you can just include it in your app as normal ASPX. But then you’d need to handle validation and postback stuff all yourself. And personally, I would begin to wonder if storing my data in a SQL database wouldn’t be easier to begin with. Especially when you’re using skilled ASP.NET developers without SharePoint knowledge to create apps.
The downside to all of this is that you’re going to end up with a webapp which has little to do with SharePoint. It’ll be just another ASP.NET web application, linked to from SharePoint. Not much more than you’d have when you just add a hyperlink to your quick launch bar. Ok, it’s single sign-on by default, hurray.
For more discussion on this, please visit my forum thread here: http://social.msdn.microsoft.com/Forums/en-US/appsforsharepoint/thread/ec475619-1688-44f8-a26d-ce5ce0cb7984