Monday, December 27, 2010

ProcessBatchData in Sharepoint

Sometimes we need to update more than one item in a list, so looping through all items in sharepoint list would not be good practice, as it degrades performance.  


The better way to do this, is through ProcessBatchData. In this we construct a CAML string  contains a batch of commands to perform the updates. Then we should execute the commands by using the ProcessBatchData command of an SPWeb object.


Each command includes a Method element with SetVar subelements. 
The SetVar elements define 

  • Type of command e.g. <SetVar Name=\"Cmd\">
  • ID of the item e.g. <SetVar Name=\"ID\">
  • Fields to update. The fields are defined in the format <schema>#<internal_field_name> e.g. <SetVar Name=\"urn:schemas-microsoft-com:office:office#PersonID\">

The Guid of the List must be specified in <SetList> tag.


After all the commands are created, they are placed in an ows:Batch element. This element contains an OnError attribute that defines what happens if an exception occurs while the commands are executed


Thats it, here is the snippet 


Batch command to add a new item to Sharepoint list

As we are going to add a new item, just specify "New" in place of ID <SetVar Name \"ID\">. I have highlighted in the below code snippet.

 using (SPSite site = new SPSite("http://sitecollectionURL"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                        SPList list = web.Lists["ListName"];
                        string listGuid = list.ID.ToString();
                        string _xmlData = "";
                   
                        SPUser theUser = web.SiteUsers[_userID];
                        SPListItem item = list.Items.Add();
                        string _personID = theUser.ID.ToString() + ";#" + theUser.Name;

                        batch = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                            "<ows:Batch OnError=\"Return\">{0}</ows:Batch>" + "<Method ID=\"{0}\">" +
                            "<SetList>" + listGuid + "</SetList>" +
                            "<SetVar Name=\"Cmd\">Save</SetVar>" +
                            "<SetVar Name=\"ID\">New</SetVar>" +
                            "<SetVar Name=\"urn:schemas-microsoft-com:office:office#PersonID\">" + _personID + "</SetVar>" +
                            "<SetVar Name=\"urn:schemas-microsoft-com:office:office#XmlData\">" + _xmlData + "</SetVar>" +
                            "</Method>";
                    
                    string batchReturn = web.ProcessBatchData(batch);
                }
            }




Batch command to update an item in the Sharepoint list

To update an item in the sharepoint list, we just need to put the item id to update in the tag <SetVar Name \"ID\">. I have highlighted in the below code snippet.


        using (SPSite site = new SPSite("http://sitecollectionURL"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                        SPList list = web.Lists["ListName"];
                        string listGuid = list.ID.ToString();
                        string _xmlData = "";
                   
                        SPUser theUser = web.SiteUsers[_userID];
                        SPListItem item = list.Items.Add();
                        string _personID = theUser.ID.ToString() + ";#" + theUser.Name;

                        batch = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                            "<ows:Batch OnError=\"Return\">{0}</ows:Batch>" + "<Method ID=\"{0}\">" +
                            "<SetList>" + listGuid + "</SetList>" +
                            "<SetVar Name=\"Cmd\">Save</SetVar>" +
                            "<SetVar Name=\"ID\">ItemID</SetVar>" +
                            "<SetVar Name=\"urn:schemas-microsoft-com:office:office#PersonID\">" + _personID + "</SetVar>" +
                            "<SetVar Name=\"urn:schemas-microsoft-com:office:office#XmlData\">" + _xmlData + "</SetVar>" +
                            "</Method>";
                    
                    string batchReturn = web.ProcessBatchData(batch);
                }
            }

      

Thursday, December 9, 2010

JQuery - What? Why? How?

What is JQuery?
JQuery is a lightweight cross-browser JavaScript library. JQuery is designed to change the way that you write Javascript.


Why JQuery?
You can use simple JavaScript to perform all the functions that jQuery provides. Then why JQuery? It easy to create nice web effects in just a few lines of code. We may require 10-11 lines of code in Javascript to perform certain function, the same thing can be achieved through JQuery with just 1-2 lines of code (as it says Write less, Do More). And its very easy to learn too.


How to use it?
You can download the source code, from the jQuery website. There will two versions "Minified" and "Uncompressed".


Minified Vs Uncompressed
The minified version is best for the production environment. It will save you some bandwidth and some loading time. It is hard to debug.
The uncompressed version is for development, you can debug it.


How to use jQuery library in our ASP.Net project?
Once you have downloaded the JQuery and include the reference to the jQuery library file in your ASPX page.
<script src="jquery-1.4.4.min.js" type="text/javascript"></script>
        <script language="javascript">
            $(document).ready(function() {
            alert('test');
            });
        </script>


Launching Code on Document Ready
jQuery has a simple statement that checks the document and waits until the DOM is fully loaded.
Next, what is this $.. We can access the JQuery object using $. We can even use "jQuery" instead of $
eg: jQuery(document).ready(function() {
            alert('test');
            });

Hope this post will give you a brief idea about JQuery. You can learn more JQuery syntax here.


Sunday, November 14, 2010

MOSS - Farm Hierarchy

Logical Components in a Farm

Farm Hierarchy


SharePoint Containment Hierarchy 


Single Sign On - Products

Single Sign-On (SSO) is a method of access control that enables a user to
log in once and gain access to the resources of multiple software systems
without being prompted to log in again. Single sign-off is the reverse
process whereby a single action of signing out terminates access to
multiple software systems.
As different applications and resources support different authentication
mechanisms, Single Sign-On has to internally translate to and store
different credentials compared to what is used for initial authentication.

Complete List of SSO products and its vendors can be found in link http://identityaccessmanagement.blogspot.com/2005/05/vendor-list.html 

SSO Products : Some of the SSO Products are
1. CAS enterprise single sign-on
2. Sun OpenSSO Enterprise
3. CA Single Sign-On
4. Tivoli Access Manager for Enterprise Single Sign-On - Its details can be found in http://www-01.ibm.com/software/tivoli/products/access-mgr-esso/
5. Novell SecureLogin
6. Entrust GetAccess
7. Sentillion - Is a Microsoft Company. It provides Vergence SSO. Details can be found in http://www.sentillion.com/expresso/index.html
8. Oracle Enterprise Single Sign-On Suite Plus - http://www.oracle.com/technology/products/id_mgmt/esso/index.html