Thursday, December 1, 2011

JQuery for the SPO world!

Getting around the Server Object Model for displaying data from multiple site collections in a site in the SharePoint Online environment... JQuery comes to the rescue...

We had a typical challenge to fetch the site collections data across multiple farms in a web part. A sandbox solution was certainly not the answer since it cannot access beyond the scope of the immediate site collection.


JQuery comes to our rescue here, I learned some amazing functionality that I would like to share....

In the below code we are trying to get the list of Site collections which have a list deployed with metadata mapped fields.

We are displaying the results in a JQuery Datatable




1. Get the css files from here http://datatables.net/index
2. Get the Jquery references libraries from here http://jquery.com/
Steps :
  1. Deploy a custom list in each of the site collections which need to be discovered - this list has the fields which will need to be mapped in central admin once the crawl has run.
  2. Create mapped search meta data properties and via JQuery fetch the code. I am using only one custom property in the code below. Learn how to map properties http://technet.microsoft.com/en-us/library/cc262933(office.12).aspx 
  3. Write your JQuery code ( below is an example to get all site collections, this can be conditionally done as well, based on a look up column of Choice Type.
  4. Upload the css and JQuery Files in the right path and map it correctly in the html file
  5. Uncomment the alerts so that you can get the values for debugging purposes.
  6. This html file can now be uploaded to the documents library and be linked from any content editor web part and we have what we need!
Please change the query based on your search metadata properties. Here's the HTML code:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  
 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" >
  
 <head>
  
   <title>My New Page</title>
  
   <style type="text/css" title="currentStyle">
  
                 @import "/Style Library/assets/css/demo_page.css";
  
                 @import "/Style Library/assets/css/demo_table.css";
  
   </style>
  
     <script type="text/javascript" language="javascript" src="/Style%20Library/assets/js/jquery.js"></script>
  
    <script type="text/javascript" language="javascript" src="/Style%20Library/assets/js/jquery.dataTables.min.js"></script>
  
    <script language="javascript" src="/Style%20Library/assets/js/jquery.SPServices-0.6.2.min.js" type="text/javascript"></script>
  
  <script type="text/javascript" charset="utf-8">
  
  var resultStatus;
  
  $(document).ready(function () {
  
  SearchForProperty ();
  
 $('#example').dataTable({ "aaSorting": [[4, "desc"]] });
  
 ShowHideTableColumn(5);});
  
  function ShowHideTableColumn( iCol )
  
      {
  
            /* Get the DataTables object again - this is not a recreation, just a get of the object */
  
            var oTable = $('#example').dataTable();        
  
            var bVis = oTable.fnSettings().aoColumns[iCol].bVisible;
  
            oTable.fnSetColumnVis( iCol, false );
  
       } 
  
           var queryText ='<QueryPacket xmlns="urn:Microsoft.Search.Query" Revision="1000">'
  
           queryText += '<Query domain="QDomain">'
  
           queryText += '<SupportedFormats>'
  
           queryText += '<Format>'
  
           queryText += 'urn:Microsoft.Search.Response.Document.Document'
  
           queryText += '</Format>'
  
           queryText += '</SupportedFormats>'
  
           queryText += '<Range>'
  
           queryText += '<Count>20</Count>'
  
           queryText += '</Range>'
  
           queryText += '<Context>'
  
           queryText += '<QueryText language="en-US" type="STRING">'
  
           queryText += '</QueryText>'
  
           queryText += '</Context>'
  
           queryText += '<Properties>'
  
           queryText += '<Property name="Title"/>'
  
           queryText += '<Property name="Path"/>'
  
           queryText += '<Property name="Description"/>'
  
           queryText += '<Property name="Write"/>'
  
           queryText += '<Property name="Rank"/>'
  
           queryText += '<Property name="Size"/>'
  
           queryText += '<Property name="YOURCUSTOMMETADATAPROPERTY"/>'
  
            queryText += '</Properties>'
  
           queryText += '</Query>'
  
           queryText += '</QueryPacket>';
  
           var SearchForProperty = function () {
  
            var results = $('#result');
  
             $().SPServices({
  
               operation: 'Query',
  
               queryXml: queryText,
  
               completefunc: function (xData, Status) {
  
                 $(xData.responseXML).find('QueryResult').each(function () {
  
                   //let's see what the response looks like 
  
                   var x = $('<xml>' + $(this).text() + '</xml>');
  
                   //     alert($(this).text());
  
                          x.find('Document').each(function () {
  
                          var Metadataproperty= '';
  
                          $(this).find('Property').each(function () {
  
                         propname = $('Name', $(this)).text();
  
                         if (propname == ‘YOURCUSTOMMETADATAPROPERTY’) {
  
                         Metadataproperty = $('Value', $(this)).text();
  
                         //alert('My custom metadata property =' + Metadataproperty); 
  
                       }                                      
  
                     });
  
                     $('#example').dataTable().fnAddData([Metadataproperty]);
  
                     $('#loading').hide();
  
                   });
  
                 });
  
               }
  
             });
  
           }
  
  </script>
  
 </head>
  
 <body>
  
 <div id="demo">
  
   <p style='text-align:right'>View the results </p>
  
   <table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
  
 thead>
  
     <tr >
  
      <th style='text-align:left'>Metadata property : values</th>     
  
      </tr>
  
    </thead>
  
 </div>
  
 </body>
  
 </html>  



 

Tuesday, May 17, 2011

Cloud Computing - Sandboxed solutions?

Sharepoint 2010 Online cloud offerings : Some insight into the Sandboxed solutions

 
 
I recently got this great opportunity to work on BPOS D env on Sharepoint online. Exploring all the options for development and deployment was a very logical next step.. Here are all my findings on the BPOS online world for Sharepoint 2010 online development..... Starting with Sandboxed solutions.. Collating all the information that I have for now.... Next will be farm solutions and all about MSOCAF...Plan is to also have some sample code that goes for these…
  • Visual Studio supports sandboxed solutions through a Boolean project property called Sandboxed Solution. This property can be set at any time in the project, or it can be specified when you create the Project
  • By using sandboxed solutions, you can deploy your solutions to a subarea of the farm, a specific site collection. To provide additional protection, the solution’s assembly is not loaded into the main IIS process (w3wp.exe). Instead, it is loaded into a separate process (SPUCWorkerProcess.exe). This process is monitored and implements quotas and throttling to protect the farm from sandboxed solutions that perform harmful activities, such as running tight loops that consume CPU cycles.

 
 
When a sandboxed solution is deployed, the array of SharePoint functionality available to it is limited to help reduce any security vulnerabilities it may have. Some of these limitations include the following
  • Sandboxed solutions have a restricted subset of deployable solution elements available to them. Potentially vulnerable SharePoint project templates, such as site definitions and workflows, are not available.
  • SharePoint runs sandboxed solution code in a process (SPUCWorkerProcess.exe) separate from the main IIS application pool (w3wp.exe) process.
  • Mapped folders cannot be added to the project.
  • Types in the Microsoft SharePoint Server 2010 assembly Microsoft.Office.Server cannot be used in sandboxed solutions. Also, only types in the Microsoft SharePoint Foundation 2010 assembly Microsoft.SharePoint can be used in sandboxed solutions.
What you CANNOT DO…
    • You cannot run your code with elevated permissions in sandboxed solution
    • You cannot use Visual web part template for sandboxed solution. Because sandbox solution cannot deploy files to web front end.
    • You cannot access internet to make web service calls directly
    • You cannot access hard drive to read/write files
    • You can’t access code that is not marked to allow partially trusted callers
    • You cannot deploy assemblies to GAC
It is especially appropriate to use sandboxed solutions in the following scenarios :
When you want to load balance solutions between multiple SharePoint Server servers.When an organization wants to run code for employees on a production SharePoint Server site, and that code has not been stringently code reviewed and tested.When an Internet hosting provider wants to let the owners of hosted SharePoint Server sites upload and run custom code.
      Plan sandboxed solutions governance
While you are still planning for sandboxed solutions, you should consider your processes for governance issues, including the following
  • At what point will the farm administrator block or unblock a sandboxed solution? Identifying the administrative policy for blocking and unblocking sandboxed solutions will eliminate confusion if there is any doubt about the need to block a solution.
  • At what point will you transfer a sandboxed solution to the global catalog as a full trust solution? This decision applies to solution code that is developed by your organization’s developers. You should establish a policy for determining what level of testing is required for a sandboxed solution to be considered ready for production use in your organization.
  • When you are planning for who can deploy sandboxed solutions, will you choose to add people to the site collection administrators group or establish a procedure for a limited number of site collection administrators to deploy sandboxed solutions on behalf of their users? Depending on the security concerns in your organization, you can decide to add people directly to the site collection administrators group rather than requiring them to ask permission to deploy the sandboxed solution.
Getting close to the CODE
Restricting the access of sandboxed solutions to a subset of the Microsoft.SharePoint namespace is intended to prevent solutions from accessing functionality that could destabilize the farm. When sandboxed solutions make calls to the SharePoint object model, the calls are routed through the subset proxy, which in turn makes calls to the full object model. Sandboxed solutions do not support the following capabilities and elements, hence the design of the solution should take care of the following
1.    Visual Web Parts
2.    Application Pages
3.    Custom Action Group
4.    HideCustomAction element
5.    Content Type Binding
6.    Web Application-scoped features
7.    Farm-scoped features
8.    Workflows with code

The subset proxy exposes only the following subset of the object model
All of the Microsoft.SharePoint namespace, except
1.      SPSite constructor
2.      SPSecurity object
3.      SPWorkItem and SPWorkItemCollection objects
4.      SPAlertCollection.Add method
5.      SPAlertTemplateCollection.Add method
6.      SPUserSolution and SPUserSolutionCollection objects
7.      SPTransformUtilities object
8.      Microsoft.SharePoint.Navigation namespace

 
All of the Microsoft.SharePoint.Utilities namespace, except
    • SPUtility.SendEmail method
    • SPUtility.GetNTFullNameandEmailFromLogin method
    • Microsoft.SharePoint.Workflow namespace
All of the Microsoft.SharePoint.WebPartPages namespace, except
    • SPWebPartManager object
    • SPWebPartConnection object
    • WebPartZone object
    • WebPartPage object
    • ToolPane object
    • ToolPart object
WORKAROUNDS…… Some pretty important things that make it work in online environment…
1.    Visual Web Part       Install the Visual Studio 2010 SharePoint Power Tools   http//visualstudiogallery.msdn.microsoft.com/8e602a8c-6714-4549-9e95-f3700344b0d9/   and you will find a new "Visual Web Part (Sandboxed)" template.
2.    Cannot deploy files on layouts folder You can use a Module to deploy files on your application, without using Document Library.
3.    Cannot use Application Pages with code behind You can deploy an application page using a Module and add a Sandboxed Web Part to use code behind. SharePoint offers a specific class name <WebPartPagesSPUserCodeWebPart > to archives this goal. At the following link you can find a good example    http//www.wictorwilen.se/Post/Custom-application-pages-in-the-SharePoint-2010-Sandbox.aspx

 
 
References

Friday, January 21, 2011

A deep Dive into BPOS D

Next week I am going for a deep dive to investigate what Microsoft has to offer for Sharepoint 2010 in the cloud...

VERY VERY EXCITED!!