Wednesday, April 23, 2014

Exporting deployed WSP's of your SP Farm

If you want to get wsp out of deployed WSP's in your fram, execute below power shell code.

Copy below lines of code to a power shell file. i.e., file with extention "ps1" and go to windows powershell command or SharePonit's and run the prepared file. 

Tuesday, April 15, 2014

Adding JavaScript/Jquery code in InfoPath forms

Some times you may face requirement to access controls of InfoPath form in javascript. Then below approaches may helpful.

Example requirement: Client asks you to handle enter key to navigate from one control to another control on the form or execute rules when user enters a value in a text box and hits enter. Usually, in infopath form, we use Tab key instead Enter key for such requirements.

To fulfill such requirements, we have to go with JavaScript code that will read the enter key number (13) and then you will make that as Tab key(if i am not wrong, i guess it is 8).

There are two ways in adding JavaScript for InfoPath forms.

Method 1) in code behind of InfoPath form
Method 2) in FormServer.aspx page in layouts folder

Method 1 will effect the script funcionality only on your form. where as method 2 will effect for all forms. because InfoPath forms will load as control on FormServer.aspx page.

In Method 2 also, you have to use delay() method in javascript before reading the controls. Because, generally the script will execute before the control i.e., form loads. writing delay(1000) will help the script wait for 1 second and in this time, the form will load and so you can read the controls based on your requirement.


For method 1, you need to write in the code as shown in below example:

//This is to handle back space key press.
 //page should not go back when user clicks backspace key. It will work as usuall when cursor is in any control
                HttpContext.Current.Response.Write("<script type='text/javascript'>" +
                    "if (typeof window.event != 'undefined')" +
                    "{document.onkeydown = function(){" +
                       "if (event.srcElement.tagName.toUpperCase() != 'INPUT')return (event.keyCode != 8);}}" +
                       "else{document.onkeypress = function(e){if (e.target.nodeName.toUpperCase() != 'INPUT')return (e.keyCode != 8);}" +
                       "}</script>");



happy coding :)



Debugging SharePoint's custom timer jobs from visual studio

I guess this topic is there in many sites. but still want to update in my blog.

when you want to debug a custom sharepoint timer job from visual studio 2008 or above, follow below steps:

1. After you deploy your timer job, you need to restart SharePoint timer service that will be available in list of windows services on your server machine.
2. Now go to debug and attach to process and select OWSTIMER process. If you are not finding it, click refresh button multiple times and check. After attaching,
3. Keep a break point in execute method.
4. go to central admin-->monitoring and find your deployed timer job and Run It using "run now" button

that's all, if you did all correct, you will see the execution will take you to the break point that you placed in your execute method.


happy codding :)
Accessing List or Library in Custom SharePoint TimerJob code of a site without Hard-codding site URL/ID

When we write any custom SharePoint timer job using visual studio, some times, we may need to access values from a list / library. and in such cases, some times you may not be predict the site ID/URL in which the list / library present.

In such scenario's the best options is to develop a feature with "site" scope. and use this feature to create timer job instance and also to get required list object. This feature GUID will be used for getting site collection where your list/library exists.

Once after creating feature, note down the GUID and now go to execute method of your timer job. In that method, you get the webapplication object and iterate through all its site collection. Now find the site collection in which the above feature with GUID is activated. Take that site collection as your SPSite object and access your required lists.

In this way, you can avoid hard coding site URL or ID. only thing you have to make sure is, this feature should be activated only in your required site collection.


Example: You have to write a timer job that will execute every week on sunday. And this job should read items from a master list called "EmployeesToBeNotified" which contains all employees to whom you have to send notifications using email.

Sample Code:

 public override void Execute(Guid targetInstanceId)
        {
               SPSecurity.RunWithElevatedPrivileges(delegate
                {
                    System.Diagnostics.EventLog.WriteEntry("TimeSheet TimerJob", "TimeSheet TimerJob Executed");
                     SPWebApplication webAppNew = (SPWebApplication)this.Parent;
                     if (webAppNew.Sites.Count > 0)
                     {
                         Guid NewSiteID =new Guid();
                         foreach (SPSite timesheetSite in webAppNew.Sites)
                         {
                             Guid featureGuid = new Guid("d5ef5623-270a-4c8c-b4c5-784b82306b87");
                             if (timesheetSite.Features[featureGuid] != null)
                             {
                                 NewSiteID = timesheetSite.ID;
                                 timesheetSite.Dispose();
                                 break;
                             }
                       
                         } //close of foreach

                             using (SPSite site = new SPSite(NewSiteID))
                               {
                                    //write your required code here.
                                }

                     } //close of outer if
                 });       //close of spsecurity
     } //close of execute method

Send email with CC and BCC using SPUtility in SharePoint

When i am searching for options to send CC/BCC using SharePoint's SPUtility class, i came across this code. Thought of sharing in my blog which might be helpful for any one



StringDictionary headers = new StringDictionary();
headers.Add(“to”, sendTo);
headers.Add(“cc”, “”);
headers.Add(“bcc”, “”);
headers.Add(“from”, “admin@test.com“);
headers.Add(“subject”, “Testing”);
headers.Add(“content-type”, “text/html”);
SPUtility.SendEmail(web,headers, Body);



share your comments/feedback if any.

thank you :)

Saturday, June 22, 2013

Stop Event bubbling in SharePoint event handler

In SharePoint event handler, when you use method like ItemUpdated() or ItemUpdating(), you may come across your handler/method code will execute multiple times. Which is very much incorrect and irritating for you.
In this scenario, you can use  "EventFiringEnabled" property and stop bubbling of events. I tried this in my event handler and worked perfectly.
given bellow is sample code that i used in my demo.



 public override void ItemUpdated(SPItemEventProperties properties)
       {
           base.EventFiringEnabled = false;

           LogEvent("entered item updated method");  //my custom logger method is used here

           SPSite site = properties.OpenSite();
           SPWeb currentWeb = properties.OpenWeb();
           SPWeb rootWeb = site.RootWeb;
           SPList currentList = properties.List;
           SPListItem rootListItem = properties.ListItem;
           rootListItem["Title"] += "modified by event handler";
           rootListItem.SystemUpdate();

           LogEvent("existing item updated method");

           base.EventFiringEnabled = true;
       }

       private void LogEvent(String msg)
       {
           SPSecurity.RunWithElevatedPrivileges(delegate()
           {
               System.Diagnostics.EventLog el = new System.Diagnostics.EventLog();
               el.Source = "DupeEventReceiver";
               el.Log = "Application";
               el.WriteEntry(msg);
           });
       }


happy codding.
Your suggestions and ideas are most welcome.

Monday, June 3, 2013

Very helpful URL's for technical information on technologies like SharePoint 2007 & 2010, InfoPath Forms, Workflows and many other which i came across. Hope it will help some one at some point of time :)


  1. Deploy web browser enabled form using feature in SharePoint
  2. Moving infopath and re-usable workflow to different server in SharePoint 
  3. Trigger a workflow programatically in SharePoint
  4. Create a Simple Image Slide Show using jQuery
  5. Microsoft sky drive location where lot of infopath sample forms can be downloaded
  6. Xpath examples and syntax
  7. Data view caching issues and other webpart property setting through custom webpart
  8. Setting webpart properites on a page. sharepoint
  9. Set master page by activating feature and action in SharePoint
  10. Alternate url creation in SharePoint
  11. Client object model, ecmascript or javascript, list based with where condition
  12. Calling javascript function on page load
  13. Rribbon customization in SharePoint
    1. http://styledpoint.com/blog/ribbon-customization-changing-placement-look-and-behavior/
  14. People search deaprtment wise quering
  15. How to open document library in infopath form
  16.  Cascading dropdowns using designer
  17.  Opening model dialogue box using javascript in SharePoint
  18. Master page SharePoint 2010 customization
  19. Customizing content query webpart and xslt dataview webpart
  20. For SharePoint and demonstration site
  21. SharePoint performance relates articles
  22. For caching of objects in SharePoint
  23. Sqlserver in C#
  24.  restrict users in FBA site
  25. LINQ
  26.  Ecma and learning sharepoint url
  27.  For video tutorials of SharePoint 2010
  28. Customizing search results using xslt
  29. Variables used in advanced search box customization