Monday, March 5, 2012

SharePoint Customization

When I tried to build site using sandbox, I found many restrictions. The better solution for most of these problems do a workarounds using out of the box controls and Web parts of the SharePoint.

I found site give us good solutions for building some modules with small customization of out of the box SharePoint Web parts and Controls with css and javascript functions:
http://usermanagedsolutions.com/SharePoint-User-Toolkit/default.aspx
It Contains solution for SharePoint 2007 and SharePoint 2010 Sample of them:
  • Color-Coding-Calendar-List:
    Display calendar with color depend on category of item in List
  • Pie and Bar Charts (Google Connector)
    Display chart using calendar chart depend on values in List
  • Easy-Tabs
    When added to a Web Part zone, the Easy Tabs automatically generate a tabbed interface, with one tab per Web Part present in the zone.
  • Cross-Site-List-Snapshot
    This script allows you to display in a SharePoint page a view taken from another site or site collection.
  • Tasks-Lists-Rollup:
    roll-up Web Part that displays items collected from multiple lists of the same type
  • Bookmarklet-Expand-Collapse-Web-PartsOn a SharePoint page:
    adds an expand/collapse button to each Web Part, next to the title.
  • Page-Redirect:
    This script allows you to redirect your users to another Web page (specified in the Target location), when they try accessing the current page.
  • Image-Rotator:
    The image rotator allows you to display on your page a picture randomly selected from a SharePoint picture library.

    You can use solutions and add more enhancement of it.







Create Poll for Sandbox or Office 365

I want to create Poll in Shared Environment that allow to create only components using Sandbox.
Sandbox has many limitation affect building this module:
  1. Cannot run component with elevated privilege or impersonate user. (Poll Component for anonymous users)
  2. Sandbox cannot serialize cookie only can read a cookie.

For these reason cannot build solution using sandbox to build a poll. Only Customize predefined controls using SharePoint Designer to build a poll.

Steps:

  1. Create 2 Lists:
    • Poll List with Fields Question(Text), Answer1(Text), Answer2(Text), Answer3(Text), Active(Yes/No)
    • Poll Result QuestionId, Answer1Count(Number Default 0), Answer2Count(Number Default 0), Answer3Count(Number Default 0)
  2. Create Workflow When you add a Poll Item in List It will add item in Poll Result.
  3. Give Add Permission of anonymous user in Poll Result.
  4. Create Active Workflow to allow only one active poll. If We activated Poll, Deactivate others.
  5. Create DataView For Displaying a Poll:
  • DataSource read the 2 lists read active poll and its results.
  • XSLT contains 2 View:
    1. Show Poll and allow user to vote. Appears if user didn't respond on this poll.
    This contains form question as title and questions as radio buttons in Forms and button for respond.
    When user click button. It will call client object model to increase selected answer count. and set cookie using JavaScript using jquery that he answer this question.
    you can use captcha using javascript:
    http://sharepointserver-2007.blogspot.com/2012/01/capatcha-using-javascript.html
    2. Show Results display Poll Result. . Appears if user respond on this poll.
    Validation that user respond this answer check if active poll Id exists in cookie that set in previous step. You can build graph for displaying results using div and style sheets.

This is simple Poll for sandbox or Office 365 you can add more enhancement.

Saturday, March 3, 2012

SharePoint 2010 Sandboxed limitation

SharePoint 2010 define a way of packaging called sandbox because old way of packaging is not suitable for shared environment. If there is a problem of package it will effect the environment. But new packaging technique will effect only sandbox's modules was deployed in this site collection.
Components of the sandbox:
  • User Code Service (SPUCHostService.exe). This is responsible for creating the sandbox worker processes that execute individual sandboxed solutions and for allocating requests to these processes.
  • Sandbox Worker Process (SPUCWorkerProcess.exe). This is the process in which any custom code in your sandboxed solution executes.
  • Sandbox Worker Process Proxy (SPUCWorkerProcessProxy.exe). This provides a full-trust environment that hosts the SharePoint API. This enables sandboxed solutions to make calls into the subset of the SharePoint object model that is accessible to sandboxed solutions.

But Sandbox has many limitations:

  1. You can use most of SharePoint API but you can only use current site collection. All you information must be saved in current site.
  2. No Security Elevation (You cannot impersonate). You can only run with current logged in user. You must give a user actual permission to access SharePoint item.
  3. No Email Support (You cannot send email). Only workaround start workflow with activity to send the mail but take care of needed permission to start workflow.
  4. You cannot use SharePoint Web Controls.(You can use asp net controls instead of it).
  5. You cannot do WebRequest connections,(http, web services, wcf, and etc). To access those use through javascript or silverlight.
  6. No GAC Deployment (Sandbox solutions are not stored in File System, they are stored in the database) C:\ProgramData\Microsoft\SharePoint\UCCache temporary for global assembly cache.
  7. Enterprise features (Search, BCS, etc.) are not allowed.
  8. CAS does not allow you to access database. All data storage in SharePoint List.
  9. CAS does not allow you access IO:
    • Global folders like “_layout” & “resources” are not authorized. To use resource file embed it in the dlls.
    • No Visual Webparts
    • No Custom workflow
    • Allow features depend on physical files are not allowed.
  10. No Threading.
  11. No P-Invoke
  12. Sandbox work in separate domain and initialize new page serialize some information to communicate with w3wp.exe.
    Serialized Information which can use in sandbox:
    • ID's of Form, Web Part Manager, Zone, Toolpane
    • Web Part properties
    • Options and properties of the Web Part and zone, such as chrome, zone customization, width, height...
    • View state
    • Control state
    • Server Variables (except APPL_PHYSICAL_PATH and PATH_TRANSLATED)
    • Request Headers
    • Input Stream
    • Current context (List Id, Item Id)
    • Query String

    Serialized Information which can use in sandbox:
    • The Cache object
    • Cookie
    • The ScriptManager or callback
    • The ClientScriptManager
    • The HttpRequest.Files collection (work with limited size to 128KB
    • The Master Page
    • Embedded resources (these are requested by the WebResource.axd and they cannot resolve the Sandboxed assemblies from the W3WP.exe process)
    • You cannot use redirection (Response.Redirect, Server.Transfer or SPUtility.Redirect)
    • You cannot export a Sandboxed Web Part (it will just export the SPUserCodeWebPart)
    • Also you cannot access page object (you cannot control hide or show controls in page like HideCustomAction and CustomActionGroup)
  13. PropertyBags of SharePoint Object model are not accessible
  14. ASP.NET 2.0 web controls are not fully working (those that are using “WebResource.axd” for internal binaries resources, as .axd extension is not allowed). Instead of embed them upload to SharePoint and refer to them as external resources.
  15. Also Sandbox limited number of resources used and deactivate sandbox solution if they reached limited number of resources. limitation depend in number of point limitation by administrator and calculated as this table:


    Metric Name

    Description

    Units

    Resources Per Point

    Hard Limit

    AbnormalProcessTerminationCount

    Process gets abnormally terminated

    Count

    1

    1

    CPUExecutionTime

    CPU exception time

    Seconds

    200

    60

    CriticalExceptionCount

    Critical exception fired

    Number

    10

    3

    InvocationCount

    Number of times solution


    has been invoked

    Count

    N/A

    N/A

    PercentProcessorTime

    Note: # of cores not factored in

    Percentage Units of Overall Processor Consumed

    85

    100

    ProcessCPUCycles



    CPU Cycles

    1E+11

    1E+11

    ProcessHandleCount



    Windows Handles

    10,000

    5,000

    ProcessIOBytes

    (Hard Limit Only) Bytes written


    to IO

    Bytes

    1E+07

    1E+08

    ProcessThreadCount

    Number of Threads


    in Overall Process

    Threads

    10,000

    200

    ProcessVirtualBytes

    (Hard Limit Only)


    Memory consumed

    Bytes

    1E+09

    4E+09

    SharePointDatabaseQueryCount

    SharePoint DB Queries Invoked

    Number

    400

    100

    SharePointDatabaseQueryTime

    Amount of time spent waiting


    for a query to be performed

    Seconds

    20

    60

    UnhandledExceptionCount

    Unhanded Exceptions



    50

    3

    UnresponsiveprocessCount

    We have to kill the process because it has become unresponsive

    Number

    2

    1

    For more details check URL:
    http://msn.microsoft.com/en-us/library/ff798382.aspx