Posts

Showing posts from 2012

javascript to get the all site user in sharepoint 2010 (Getting all Site users using Client Object Model)

 If you want to get the all sharepoint site users and their groups you need to do following steps Step1: open notepad and paste below script in that and save that file with the extension of ".js" ExecuteOrDelayUntilScriptLoaded(retrieveAllUsersAllGroups, "sp.js" ); function retrieveAllUsersAllGroups() { var clientContext = new SP.ClientContext.get_current(); this .collGroup = clientContext.get_web().get_siteGroups(); clientContext.load(collGroup); clientContext.load(collGroup, 'Include(Users)' ); clientContext.executeQueryAsync( Function .createDelegate( this , this .onQuerySucceeded), Function .createDelegate( this , this .onQueryFailed)); } function onQuerySucceeded() { var userInfo = '<tr>' ; var grouname = '<tr>' ; var text = "<table><tr><th>GroupName</th><th>GroupMembers</th></tr>" ; var groupEnumerator = collGroup.getEnumerator(...

Disable all day event, Recurrence,Workspace Fields in Calendar list

Open the Newform.aspx in edit mode( <site>/Calendarlist/Newform.aspx?toolpaneview=2) and add the content editor webpart to below the form and paste the below script in html editor of the content editor web part. < script type = "text/javascript" > function HideField(title){ var header_h3 = document .getElementsByTagName( "h3" ) ; for ( var i = 0 ; i < header_h3.length; i ++ ) { var el = header_h3[i]; var foundField ; if (el.className == "ms-standardheader" ) { for ( var j = 0 ; j < el.childNodes.length; j ++ ) { if (el.childNodes[j].innerHTML == title || el.childNodes[j].nodeValue == title) { var elRow = el.parentNode.parentNode ; elRow.style.display = "none" ; //and hide the row foundField = true ; break ; } } } if (foundField) break ; } } HideField( ...

Auto associate workflow with list programmatically (sharepoint2010)

  private void AssociateWorkflow (SPWeb web) { SPList assocList = web.Lists[ "TestWFList" ]; SPList wflHistoryList = web.Lists[ "Workflow History" ]; SPList wflTaskList = web.Lists[ "Tasks" ]; SPWorkflowTemplate wflTemplate = web.WorkflowTemplates.GetTemplateByName( "TestWF" , System.Globalization.CultureInfo.CurrentCulture); SPWorkflowAssociation wflAss = SPWorkflowAssociation.CreateListAssociation(wflTemplate, "Custom_Approval_WorkFlow - Workflow11" , wflTaskList, wflHistoryList); wflAss.AutoStartChange = false ; wflAss.AutoStartCreate = true ; wflAss.AllowManual = true ; web.AllowUnsafeUpdates = true ; if (assocList.WorkflowAssociations.GetAssociationByName(wflAss.Name,System.Globalization.CultureInfo.CurrentCulture) == null ) { assocList.WorkflowAssocia...

Navigate or redirect NewForm.aspx to another page (Sharepoint 2010)

Hi, Here i'm going to explain how to redirect the page from newform.aspx to another page after clicking the cancel or save buttons.  here i'm giving the small example: create a application page and paste the below script in PlaceHolderMain for the test purpose < script type = "text/javascript" > function openwindow() { window .open( "http://localhost:5010/Lists/TestList/NewForm.aspx?Source=/_layouts/ModelDailogBoxSolution/Closepage.aspx" , "mywindow" , "menubar=1,resizable=1,width=350,height=250" ); } < /script> <a href= "javascript: openwindow()" > testing </a> This is the test page, you can use this code according to your requirement

How to Hide Top Bar, Ribbon, Quick Launch in SharePoint 2010?

Hi, Here i'm going to explain How to Hide Top Bar, Ribbon, Quick Launch in SharePoint 2010. Top Bar, Ribbon, Quick Launch are come up with Application Pages by default. If you want to open the page in Dialog Framework then those elements will take more space and make the layout cluttered. One way to hide these controls is by passing a Parameter with the URL. [ ?IsDlg=1 ] SharePoint will hide these elements when It gets IsDlg Parameter on URL.  Eg:   http://localhost:5010/Lists/TestList/NewForm.aspx?IsDlg=1 But every time we can't pass these parameters. Then how to get rid of these elements? Simple Just add the below css Code in Application Page under PlaceHolderMain section. < style   type ="text/css">      #s4-ribbonrow ,  .ms-cui-topBar2 ,  .s4-notdlg ,  .s4-pr   s4-ribbonrowhidetitle ,  .s4-notdlg   noindex ,  #ms-cui-ribbonTopBars ,  #s4-titlerow ,  #s4-pr   s4-notdlg   s4-titlerowhideti...

Activate SharePoint Server Publishing Infrastructure Programmatically (SharePoint 2010)

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; using Microsoft.Office.Server; using Microsoft.Office.Server.Audience; using Microsoft.SharePoint; using Microsoft.SharePoint.Administration; using Microsoft.SharePoint.Navigation; namespace ConsoleOperations {     class ActivatePublishingFeature     {         static void Main(string[] args)         {             try             {                 using (SPSite site = new SPSite("http://localhost:5012/"))                 {                     using (SPWeb web = site.RootWeb)                     {                         Guid sitePub...

Add multiple target audience groups to SharePoint Quick Launch Node

private void SetAdminViewAudience(SPNavigationNode node)         {             if (quickLaunchItem.Properties.Contains("Audience"))             {                 node.Properties["Audience"] = ";;;;" + Group1+","+ Group2 +","+ Group3+","+etc... "";             }             else             {                               node.Properties.Add("Audience",  ";;;;" + Group1+","+ Group2 +","+ Group3+","+etc... "" );             }             node.Update();         }

Modifying web.config programatically (SharePoint2010)

Here i'm going to add 2 web.config entries through code first i'm taking the backup copy of the original web.config and i'm adding the new entries. Code shown below... using System ; using System.Collections.Generic ; using System.IO ; using System.Linq ; using System.Text ; using Microsoft.SharePoint ; using Microsoft.SharePoint.Administration ; using System.Web.Administration ; using System.Configuration ; using System.Web ; using System.Web.Configuration ; using System.Reflection ; using System.Xml ; using System.Xml.Xsl ; using System.Xml.Serialization ; using System.Xml.XPath ; namespace ConsoleApplicationWebConfigBackUp { class Program { static void Main ( string [] args) { ApplyWebConfigModifications( "http://localhost:5050" ); //Taking the backup of the web.config file string physicalPath = oSite.WebApplication.IisSettings[SPUrlZone.Default].Path.ToString(); File.Copy(physical...

Finding the Web.config file of SharePoint Site Programatically (Sharepoint2010)

using System; using System.Collections.Generic; using System.Collections; using System.IO; using System.Linq; using System.Text; using Microsoft.SharePoint; using Microsoft.SharePoint.Administration; using System.Collections.ObjectModel; namespace ConsoleOperations {     class SharepointWebConfigProgram     {         static void Main(string[] args)         {             using (SPSite oSite = new SPSite("http://localhost:5050"))             {                 string physicalPath = oSite.WebApplication.IisSettings[SPUrlZone.Default].Path.ToString(); //Find the physical path of the Site                 Console.WriteLine(physicalPath + @"\web.config");                 Console.ReadLine(); //Copying The Web.config file           ...

Adding Navigation Links To Quick Launch Bar Programatically (SharePoint 2010)

using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SharePoint; using Microsoft.SharePoint.Administration; using Microsoft.SharePoint.Navigation; using Microsoft.SharePoint.Publishing; namespace ConsoleOperations {     class AddingNavigationLinks     {         static void Main(string[] args)         {             using (SPSite site = new SPSite("http://localhost:5030"))             {                 site.AllowUnsafeUpdates = true;                 using (SPWeb web = site.RootWeb)                 {                     SPNavigationNodeCollection nodeColl = web.Navigation.QuickLaunch;                    ...

Set Audience for Quick Launch Navigation Links Programmatically

using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SharePoint; using Microsoft.SharePoint.Administration; using Microsoft.SharePoint.Navigation; namespace ConsoleOperations {     class TargetAudienceToNavigationNodes     {         static void Main(string[] args)         {             using (SPSite site = new SPSite("http://localhost:5030"))             {                 using (SPWeb web = site.RootWeb)                 {                     SPNavigationNodeCollection nodeColl = web.Navigation.QuickLaunch;                     SPNavigationNode nodeHeader = new SPNavigationNode("TestNode", @"Lists/Tasks/AllItems.aspx", false);     ...

re-ordering navigation for quick launch section (SharePoint2010)

using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SharePoint; using Microsoft.SharePoint.Administration; using Microsoft.SharePoint.Navigation; namespace ConsoleOperations {     class MovingNavigationLinks     {         static void Main(string[] args)         {             using (SPSite site = new SPSite("http://localhost:5030"))             {                 site.AllowUnsafeUpdates = true;                 using (SPWeb web = site.RootWeb)                 {                     int moveToHeadingIndex = 0;                     var nodesToMove = new List<SPNavigationNode>();       ...