Article 10 from 30 : Creating a Custom Action for SharePoint 2013 App


 

This post is article-10 from the 30 Articles App series for SharePoint.

An App can have custom action in the host web.

When I say an App it relates to all kind of SharePoint app ( sharepoint-hosted/ auto-hosted / provider-hosted )

How to create it?

  1. Open your Sharepoint App project in Visual Studio.
    Add new Item-> UI Custom Action -> Add it.
    20121023-214739.jpg
  2. Enter custom action code into the element.xml file as per your target location in ribbon and/or ECB menu and list types for this custom action. (This is similar to SP2010)

Custom action at ECB menu : (1)
<CustomAction Id=”d960b369-1187-4893-b892-8a43383541b7.HostWebCustomAction1″
RegistrationType=”List”
RegistrationId=”101″
Location=”EditControlBlock”
Sequence=”100″
Title=”Invoke MyApp’s custom action”>
<UrlAction Url=”~appWebUrl/Default.aspx?{StandardTokens}” />
<!–CustomAction>

Custom action for Ribbon area : (2)
<CustomAction Id=”75dd24d9-0c16-4ef5-be0a-f52ed0e620fa.HostRibbonCustomAction1″
RegistrationType=”List”
RegistrationId=”101″
Location=”CommandUI.Ribbon”
Sequence=”100″
Title=”Invoke MyApp’s Ribbon custom action”>
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition Location=”Ribbon.Documents.Manage.Controls._children”>
<Button
Id=”Ribbon.Library.Connect.PropertyViewer”
Alt=”Invoke MyApp’s Ribbon custom action”
Sequence=”100″
Command=”Invoke_CustomAction”
LabelText=”Invoke custom action”
TemplateAlias=”o1″/>
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler
Command=”Invoke_CustomAction”
CommandAction=”~appWebUrl/Default.aspx?{StandardTokens}”/>
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>

Make sure that you put the correct CommandAction url : ~appWebUrl is for sharepoint-hosted App and ~remoteAppUrl should be used in context with remote-hosted App.

How to access it on SP host web?

Custom actions are placed into ribbon area and/or ECB menu.

As here I have chosen Document Library as target list template => select a document => expand the (…) menu and also check the ribbon area to find custom actions.

Here is how it looks after deploying the app to your host.

20121023-214749.jpg

Article 9 from 30 : Is it possible to create Mobile App for the SharePoint 2013 app web?

This post is article-9 from the 30 Articles App series for SharePoint.

In this article we will find out some technical limitation or may overcome it somehow πŸ˜›

Recently, this thought is surrounding my mind and my time πŸ™‚

Question : Can I create a Mobile Native App that talk directly to the App web. To simplify the scenario let’s say Windows Mobile App.
Link to my question I asked in the MSDN forum is here.

Scot Hillier (SharePoint MVP) has suggested a nice idea about architect it the other way
Here is what Scot says when I asked him the same question:
” “create a mobile app for SharePoint app web”, I’m scratching my head a bit wondering why. I have not tried yet, but it seems that in theory you could enter the URL of the app web into the phone app development wizard and see the available lists. I’d have to try. But again, why?
Why not either build the phone app against a SharePoint list in the SharePoint farm or build a phone app against a cloud data source – like a RESTful endpoint. In both cases, a SharePoint app could utilize the same data. So you could have a phone app and a SharePoint app (and an Office app, too).
So it seems to me there are better ways to architect the solution.”

However I still want to investigate this approach for some hidden challenges :

  1. Your client is not happy to give create list permission to the Host web for your app [50% will not allow to create a list for some App into your farm ; rest 50% would prefer if the App doesn’t ask for such permissions… my opinion ]
  2. In addition to (1), If you have to create SharePoint Artifacts then you can’t go with Cloud source
  3. As per my knowledge No one has tried this yet and so I have to try this to see what else is there beyond theory !!

Below is what I am getting while trying to create Mobile App for my App web :

An error : “The remote server returned an error : (403) Forbidden.”

20121017-154039.jpg

I am in search of a way for getting rid of this error if possible. Would love to hear your opinions on this.

Shall I count this error as “NO” to the question and consider it as the technical limitation of SharePoint 2013 App Model? Are the app webs not accessible through apis ?…. will make an update here stay tuned !!

UPDATE [ added on 19/10/12 11:00am ]

It looks like no native mobile app can talk directly to app web. May be It’s not supported. However I am still waiting for confirmation.

So for now, In conclusion to chose the best practice in context with Mobile devices : Mix of auto-hosted and/or provider hosted is one of the option which is preferable. Again keep in mind that if the App is to be subject of high scalability then tons of money + time for maintaining that data in cloud will be required. Well designed HTML App can be your saver for Mobile devices headache..!!

Also have a look to Rainer’s comments below on this subject.

I hope this RND and possible workarounds will help you to choose right approach if you are considering building native mobile app for an SharePoint app.

Have a nice weekend you all and we will meet again for next article πŸ™‚ !!

Note : This article up to above updates was written for SharePoint 2013 preview.

UPDATE : [ Added on 09/11/2012 16:30 ]

Note : SharePoint 2013 RTM has been released on 24 October 2012.

So finally I have received a reply and confirmation from Microsoft Insider( Rob M. Howard) that it is actually possible.

I am not sure that this is the change from preview to RTM or it was actually supported in preview as well.

Huge thanks to the Sharepoint App product team and to Rob for this confirmation.

The good news is yes it is supported in SP2013.

In addition to this; to understand how this works here is what Rob says

“Yes, it is possible. You would authenticate the app web the same way you would authenticate to any other web in the SharePoint site. For example, you can authenticate to SharePoint Online webs in Windows Phone applications using the procedure described at the link below:

http://msdn.microsoft.com/en-us/library/jj163079(v=office.15).aspx#SP15Mobileclientauth_advance

For SharePoint Online authentication from mobile apps in general, you can load a browser control for the user to authenticate to SharePoint, and then retrieve the authenticated cookie from the browser control and use it on subsequent requests made by your application. “

Hope that helps..!!

Article 8 from 30 : Creating an App-Part for SharePoint 2013 Apps

This post is article-8 from the 30 Articles App series for SharePoint.

An App part is similar to webpart for your SharePoint App.

How to create it?

  1. Open your Sharepoint App project in Visual Studio.
    Add new Item-> Client webpart-> Add it .
  2. Add your clientwebpart page HTML/ASPX
    here I have created ClientWebpartPage.ASPX.
    Make sure that you have put allowframing into your page.
    <WebPartPages:AllowFraming ID=”AllowFraming1″ runat=”server” />
  3. Open the element.xml file you have created from step -(1)
    and give the reference to the file you have added into step -(2) as below
  4. <?xml version=”1.0″ encoding=”utf-8″?>
    <Elements xmlns=”http://schemas.microsoft.com/sharepoint/”&gt;

    <ClientWebPart Name=”AppPartDemo_ClientWebPart” Title=”AppPartDemo” Description=”AppPartDemo_ClientWebPart Description” DefaultWidth=”250″ DefaultHeight=”300″>

    <Content Type=”html” Src=”~appWebUrl/Pages/ClientWebPartPage.aspx” />

    </ClientWebPart>
    </Elements>

How to Add it to SharePoint Page?

Simple just like you add a webpart.

Edit page-> insert webpart -> Apps -> choose your app part and save the page.

Here is how it looks after Adding my twitter App Part to SP Host.