Pages

Tuesday, July 24, 2012

Metadata Navigation in SharePoint 2013

This time post is about exciting taxonomy navigation feature in SharePoint2013. by now we all know that Managed Metadata / Taxonomy is feature introduced with SharePoint 2010 and got huge fan base. however there was always need to have the terms used in the site navigation and for that nothing was given by SharePoint as out of the box , so developer guys needed to write some code to get the terms in the navigation.

Now SharePoint 2013 has come up with the awesome feature called as metadata navigation , which is in short having your taxonomy terms in your custom navigation for site with more friendly way. lets take a look how

I am using Office365 preview and created a brand new publishing site. as usual - go to the site settings page and under look and feel you will be able to see a link which says - Navigation. click on it and you will be redirected to the site navigation settings page which looks like this

you will be able to see the added radio buttons in the Global and current navigation settings of site. under which another extra setting exists which asks you to select the term set which you want to use as metadata navigation provider. meaning that terms under this term set will appear in the navigation. all right lets create a term set using traditional link under site management - Term Store Management.

I have created the Term Set name News which contains some terms which will appear in site navigation.

Note that If you want to create your own term set and you expect that the terms under this term set should appear in the navigation - then you should do following setting
Create your term set- after creation - go to the Intended use tab - and check the checkbox which says use this term set for site navigation.


Now click on the individual term and again check the settings available in tab appearing at the top of details pane.
the most awesome thing about this feature is - you can configure the term navigation as the way you want using these settings - like

Node Name - Name of the node in the navigation
Hover Text - Hover text on mouse hover of node
Menu visibility - Specify whether this node should appear in which navigation menu
Link to header - you can provide your custom link location for header
Term Driven Page - If you do not provide the custom link location for header then on click of node , you will be redirected to user friendly url like - http://yoursite/subsite/energy


and few more settings in

Friendly URL customization - you can customize the friendly url of term
Target page settings - you can mention the page page which will be loaded when you click on term in navigation and navigate to the friendly url , example I have created a Energy.aspx page in the Pages library of the site and mentioned url of this page.
SEO Settings - you can even configure the search engine optimization related settings for individual term navigation node.



Once this all is done - again navigate to the Site Settings > Navigation page and under term set selection select the term set which you just created , click ok and you should be able to see your metadata navigation.



observe the urls , you can now go ahead and play around more settings of this nice feature. enjoy..

Saturday, July 21, 2012

Office365 Preview Development - Using Visual Studio

..continuing with the Office365 preview and development one of the most anticipated and my favorite feature is given by Visual Studio 2012, what is that? lets see

looking back at SharePoint 2010 and Visual Studio 2010 days - we were able to create the SharePoint projects using built in project templates given by VS for SP 2010 - but the disadvantage of using this project template was we had to install on the SharePoint on machine itself, we couldn't just create the wsp project on local machine with VS 2010 installed and then deploy the wsp to the server.

So whats new now?
Well with the visual studio 2012 RC - there is enhancement done for those who deal with Office365 / SharePoint 2013.  we can create a app project and deploy it on the OnPremise or on cloud SharePoint directly. just need to mention the site URL and we are done. visual studio takes care of deploying and installing the app package for you.

Once you install Visual Studio 2012 RC on your machine - install the Office Project Templates using this link. (download the tools under tools section). after this is done - you will be able to see the SharePoint project templates in VS 2012 RC.

Lets create a sample app project and deploy it directly on Office365 preview SharePoint site.



 Click ok, next step is to enter name URL of SharePoint site on which you want to deploy this app. now interesting point here is you can either add the url of your on premise SharePoint server site or add url of your Office365 site.



again - it asks you to select the type of deployment of your app. there are two types of SharePoint app deployment.

1. SharePoint Hosted - everything remains in SharePoint , complete code runs on client.
2. Cloud Hosted  - when app contains some server side code the this deployment type is selected.
     this is again subdivided into two types
         a. Developer hosted - app developer should bring his own deployment infrastructure.
         b. Auto hosted - SharePoint takes care of deployment of package itself.
For more information - please take care of great video series by Andrew connel here.

we will select the SharePoint hosted app and click finish. VS 2012 RC opens up app editor.
Lets take a closer look at solution explorer which looks like this


Feature - a default feature which takes care of provisioning app entities to SharePoint
Content - application css file
Images - app image
Pages - application's default landing page
Scripts - application js file - all JavaScript files undergo this folder.

There is AppManifest.xml which contains app settings such as


App Title , Name , App Icon and App Default start page

Permission Request - If there are certain resources of the site collection / service applications needs to be accessed by the app - it should be mentioned in the permission requests , when app will be installed - a permission request will be made by the app to the user.

Feature Prerequisites - If app required certain feature of the web to be activated before its use then it is mentioned in feature prerequisites.


when this app is run - you should see welcome message - displaying this welcome message is handled in a js file where ECMA script / JSOM for SharePoint is used to retrieve the user name of the current user.


You can add / modify the js as you wish and can start building and deploying your app on your office365 preview site.

Have fun.



Thursday, July 19, 2012

Future of Office365 Development - Napa

After release of consumer preview of SharePoint 2013, some of us were quick enough to get on installing bits , however as a quick process to see the feature set included in latest version of SharePoint some folks went directly to the Office365 preview which has SharePoint2013 and Office2013 services.

As everybody seems to take more interest in apps in SharePoint 2013 , Microsoft is kind enough to publish a app called as Napa for developers, using Napa custom apps can be created. interesting ? lets see how

If you are also one of those who are interested to take a look at Office365 preview - you can get yourself here and sign up. once you do that you will be given a admin console for office365 preview. something like this


wait for sometime as Office365 provisions a team site for you -once this is done go ahead and visit the SharePoint site , it will be something like this.



Notices dome changes ? oh yes SharePoint has gone Metro. everything is app in SharePoint now. why did I say that? take a look here and you will agree


noticed the change? the create button is replaced by add an app.
coming back to the original post topic point , what is and where is Napa?
Lets create a developer site using Office365 admin console, developer site is special site template given by SharePoint.
once it is created - browse the site - go to view all site content and click on add an app. once you click on this option you will be navigated to the app store. on left navigation you will see SharePoint store. click on it and you will be navigated to this page



go ahead and Napa app to your site. once you add the Napa app to your site , you will see the link to Napa in left navigation of your developer site. click on it to get started developing your app.
we will create a SharePoint App and will call it as HelloWorld App


after click on create button , Napa creates a basic project schema for you in browser based editor. If you observe ,In content folder it creates application specific css file, then it creates a Default.aspx page in pages folder which will be home page for your app, in Images folder you can add images needed for your app and in scripts folder you will be able to add the scripts needed to be included in your site.



so first lets simply try to run the app , Napa editor first packages the app , installs the app to your developer site and launches it for you. without writing a single line of code - running app looks something like this


You can go ahead and do your custom SP coding using ECMA and apply your own styles.
have fun..



Tuesday, June 5, 2012

How to get user picture using Lync APIs


I was exploring the Lync APIs after installing Lync SDK on my machine and as a curiosity tried to display the users communicator / Lync Image in custom control.

To get the following example working – you will need to install the Lync SDK or add the references of Lync APIs to your project. Lync SDK can be downloaded here , after this – add the references from location [%root%]\Program Files (x86)\Microsoft Lync\SDK\Assemblies\Desktop\Microsoft.LyncModel.dll to your project.

I created one sample Silverlight project where I took Silverlight image control and tried to provide the source. This control takes source as either full path of image or you can assign the BitMap Imag stream.

I created one entity class named – UserEntity which holds BitMapImage as a property.
public class UserEntity
{
    public BitmapImage UserImage { get; set; }
}

Here is the xaml for Silverlight control , Binding is added as BitMapImage stream

<Image Name="userImage" Source="{Binding Path=UserImage}" Margin="2,2,2,2" Height="40" Width="40"></Image>

Now the function to get user image

public partial class MainPage : UserControl
{
  List<UserEntity> allUsers = new List<UserEntity>();
  LyncClient client;
    public MainPage()
  {
    InitializeComponent();
    client = LyncClient.GetClient();
   
    UserEntity userObjet = new UserEntity();

    if (client != null)
    {                    
       ContactManager cManager = client.ContactManager;
       if (cManager != null)
       {
         Contact contact = cManager.GetContactByUri("useremail@domain.com");
         if (contact != null)
         {
           List<ContactInformationType> ciList = new List<ContactInformationType>();
           ciList.Add(ContactInformationType.Photo);
           IDictionary<ContactInformationType, object> dic = null;
           dic = contact.GetContactInformation(ciList);
           if (dic != null)
           {
             Stream photoStream = dic[ContactInformationType.Photo] as Stream;
             if (photoStream != null)
             {
               BitmapImage userImageBitMap = new BitmapImage();
               userImageBitMap.SetSource(photoStream);
               userObjet.UserImage = userImageBitMap;
             }
           }
         }
      }
    }
         allUsers.Add(userObjet);
  if (allUsers != null && allUsers.Count > 0)
         {
           userImage.ItemsSource = allUsers;
  }
  }

Monday, June 4, 2012

How to Initialized Client Context in Office 365 / Claim Based Authenticated Sites

Problem:

Generally we initialize the client context straight away by creating new object of class ClientContext and by providing the url of the site as well as needed credentials, but for sites using claims based authentication (let it be Office 365 site or On Premise site) this logic won’t, so what’s the solution?

Solution:
User must be logged in to the Federated Authentication Provider before initializing the client context object and hence there should be some provision in the client application to let users log in.
Microsoft has released a sample console application which demonstrates about remote authentication in SharePoint Online / Claim based SharePoint sites using managed client object model.

Hope this helps someone.

Tuesday, May 29, 2012

Export Import SharePoint Site using Web Service

Problem:

While working with SharePoint Online – sometimes it is required to take the backup of the site or to export the site to some other environment, but due to no access to SharePoint server, we end up with writing huge code to migrate the site contents to another site using any client object model.
If server side scenario is considered, we have lots of options to perform a simple site export and import operation , like say – use stsadm commands , use Central Administration , use powershell scripts but for SharePoint Online environment what to do? Well here comes web services in picture , how? We will see in details.

Solution:
SharePoint Web services are already there since MOSS 2007, but mostly not used. Here we are going to use the sites.asmx web service to export and import the sites.
Note that before performing these operations using web services – make sure that you have site collection administrator rights on source as well as target site.
I created a Team site as source site and added some sample data to it , say about 4000 documents + 3000 list items with attachments + some content types + some site columns + some lookup columns + some list and content type workflows.

We can use the ExportWeb function given by the sites.asmx web service which takes some parameters as input – let’s see what those are.
  • 1.       jobName: this is the string parameter and can be set to any string , using this name the cmp files will be created. Please make a note that no special characters are allowed here.
  • 2.       webUrl: url of the site which needs to be exported as cmp files.
  • 3.       Datapath: path where all cmp files will be stored (typically a path of the document library on source site)
  • 4.       Includesecurity: as name suggests – Boolean parameter to include security or not
  • 5.       Overwrite: Boolean parameter to overwrite cmp files on save location
  • 6.       cabSize: size of each cmp file , can be set to 2GB max.
  • Export web function returns an integer after completion , but mostly the description is not available for the return types. 
Here it is :

Value
Description
1
Pending: The operation is in progress.
4
InvalidExportUrl: The site specified in the webUrl is not accessible.
5
ExportFileNoAccess: The location specified in the dataPath is not accessible.
6
ExportWebNoAccess: The user does not have the required permissions to execute this operation successfully. The user MUST have the ManageLists and AddListItems permissions in the solution gallery.
7
ExportError: An error other than the errors listed in this table occurred during exporting the site. An example of a condition that would result in this error is if there was no content on the site to export.
8
UploadDataError: The content migration package file is not uploaded to the server successfully. This can occur if the specified path was invalid, read-only, the caller is not authorized to access it, or the file is already open.

ImportWeb:
While importing the web from cmp files using web services – we can use ImportWeb function of sites.asmx web service.

Important part here is – the target site on which import is to be done – should be created using OOB blank site definition. There can be an error while performing the import operation like – the source site is created using template STS#0 and target site is created using STS#1 , - solution to this is – create target site collection without any template – select the select template later option while creating target the site collection.
ImportWeb function take some parameters let’s see what those are
  • 1.       jobName: string parameter , can be set to anything – but no special characters should be included.
  • 2.       webUrl: url of target web.
  • 3.       dataFiles: this is array of string containing url of all cmp files. Example : If there are 10 cmp files in the source location – then dataFiles parameter will be any array having urls of 10 files in ascending order.
  • 4.       logPath: path where log file can be created. This can be passed as null. (typically a url of any document library)
  • 5.       includesecurity: to include security or not
  • 6.       overwrite: overwrite log files.
Similar to ExportWeb function – ImportWeb function also return an interger on completion.
Here are the details

Value
Description
1
Pending: The operation is in progress.
2
GenericError: An error other than the errors listed in this table occurred importing the site.
4
InvalidImportUrl: The site specified in the webUrl is not accessible.
5
ImportFileNoAccess: At least one location specified in dataFiles is not accessible.
6
ImportWebNoAccess: The user has insufficient permission to import to the location specified in webUrl.
8
mportWebNotEmpty: The location specified by webUrl corresponds to an existing site that is not a blank site.
11
LogFileNoAccess: The location specified by logPath is not accessible.

Ok , so after lots of theory – here is the simple console application example which I tried on my environment successfully.

static void Main(string[] args)
{
    string sourcesiteurl = "http://sourcesitecollection/";
    string targetsiteurl = "http://targetblanksitecollection/";
    string svcUrl = "_vti_bin/sites.asmx";

    Sites sites = new Sites();
    NetworkCredential credentials = new NetworkCredential("username", "password", "domain");
    sites.Credentials = credentials;
    sites.Timeout = 600000;

    Console.WriteLine("Choose..1. Export , 2. Import");
    string responce = Console.ReadLine();

    if (responce.Equals("1"))
    {
       sites.Url = string.Format("{0}{1}", sourcesiteurl, svcUrl);
       try
       {
         int result = sites.ExportWeb("MyExportTest", sourcesiteurl, "http://sourcesite/Exports", true, true, true, 1024);
         Console.WriteLine("done with result - " + result.ToString());
       }
       catch (Exception ex)
       {
          Console.WriteLine(ex.Message);
          Console.WriteLine();
          Console.WriteLine(ex.StackTrace);
       }
     }

     else if (responce.Equals("2"))
     {
         sites.Url = string.Format("{0}{1}", targetsiteurl, svcUrl);
         string[] dataFiles = new string[] { "http://sourcesite/Exports/MyExportTest.cmp" };
         
          try
          {
            int result = sites.ImportWeb("MyExportTest", targetsiteurl, dataFiles, null, true, true);
            Console.WriteLine("done with result - " + result.ToString());
          }
          catch (Exception ex)
          {
            Console.WriteLine(ex.Message);
            Console.WriteLine();
            Console.WriteLine(ex.StackTrace);
          }
       }
     Console.ReadLine();
   }



Monday, April 23, 2012

Add ECB Menu to any field in SharePoint porgrammatically

After long research on this - came up with something like this , however there are lots of approaches already available on net which shows you to do the same using SharePoint designer or by creating new column.
Thanks to improved SharePoint 2010 APIs which gives the SPField.ListItemMenu property , but one thing to note here is setting this property to true does not reflect the changes , before setting this property - MSDN documentation says that you need to set the SPField.ListItemMenuAllowed to Required.


try
{
   SPContext.Current.Web.AllowUnsafeUpdates = true;

   SPList list = SPContext.Current.Web.Lists.TryGetList("Cities");
   SPField countryField = list.Fields.GetField("Country");
   if (countryField.ListItemMenuAllowed == SPField.ListItemMenuState.Prohibited || countryField.ListItemMenuAllowed == SPField.ListItemMenuState.Allowed)
   {
       countryField.ListItemMenuAllowed = SPField.ListItemMenuState.Required;
   }
    countryField.ListItemMenu = true;
    countryField.Update();
    list.Update();
    SPContext.Current.Web.Update();

    SPContext.Current.Web.AllowUnsafeUpdates = false;

 }
 catch (Exception ex)
 {
    this.Controls.Add(new LiteralControl("Error: " + ex.Message));
 }

Hope this helps someone.