Open List attachments in new tab/window

Hello Floks,

Recently one my client is looking for solution in which all the list item attachment should be open in new tab or window as they have compare more than one files simultaneously.

There is a very easy solution to make it feasible. Open you List Edit/Disp Form and add below JavaScript inside it.

 $('#idAttachmentsTable a').attr('onclick','');
 $('#idAttachmentsTable a').attr('target','_blank');

Above code remove On Click event from all of the list attachment and add target as blank.

Enjoy.. 🙂 Happy Coading… 🙂 🙂

USE OF DEFERRED OBJECT IN SHAREPOINT JSOM

In previous post I explain use of Deferred Object in SharePoint REST API. In this post I’m going to explain use of Deferred object in JSOM/CSOM.

To use client context in the JavaScript you need to as below files in your page or masterpage as reference which is available in /_layouts/15/ folder.

  • inheritMicrosoftAjax.js
  • sp.runtime.js
  • sp.js

JQuery Deferred object can be used here too to make things simple, we have created a small example for that too.

functionToCall().done(function (returnedValue) {
     // do something with the returned value
});

function functionToCall() {
     var dfd = $.Deferred(function () {
     var valueToReturn = clientContext.get_web();
     clientContext.load(valueToReturn);
     clientContext.executeQueryAsync(function () {
               dfd.resolve(valueToReturn);
          },
          function (sender, args) {
               //throw an error
          });
     });
     return dfd.promise();
}

Hope this will help you and save your time..

Happy Coading… 🙂

Thanks, Jay Doshi

Use of Deferred Object in SharePoint Rest API

I have one issue in the project in which I have to update two lists item. Once first list item would updated then and then another list item would be updated. I have done Googling and get to know that we can handle two asynchronization call once first is executed. JavaScript API offers conecpt of Deferred Object which supports this type of functionality.

To communicate with SharePoint, developers mostly use SharePoint Rest API for better speed and performance.

The SharePoint Rest API can be used by inheriting the SP.RequestExecutor.js which available at the “…/_layout/15/” folder of SharePoint.

When there is requirement in which first asynchronous call is dependent upon another asynchronization call’s output at that time you can use concept of Deferred Object in JavaScript. For that we will need to control the calls sequences. But as we all know the fact that JavaScript is asynchronous and the flow of asynchronous calls cannot be controlled.

The JQuery Deferred object maintains an asynchronous call and it returns a Promise object when the call is complete.

The Promise object has two main methods to use,

done(fnSuccess, fnError, fnInProgress)
then(fnSucess)

I have created a small example of using JQuery Deferred object as shown below,

functionToCall().done(function (returnedValue) {
     // do something with the returned value or make another call here
});

function functionToCall() {
     var dfd = new $.Deferred();
     var executor;
     executor = new SP.RequestExecutor(appweburl);
     executor.executeAsync({ 
                             url: queryUrl, 
                             method: "GET", 
                             headers: {"Accept": "application/json; odata=verbose"},
                             success: onSuccess,
                             error: onError
                           });
     
     function onSuccess(data){
          var myVar = data.d.results;
          dfd.resolve(myVar);
     }

     function onError(data, errorCode, errorMessage){
          dfd.reject('Failed to load due to : '+errorMessage);
     }
return dfd.promise();
}

Additional things which needs to be consider while working with Deferred object:

  • Make sure the success and error handler are inside the async function so that the deferred object (dfd) remains global to them.
  • Both success and error handler should have deferred resolve and deferred reject methods.

Enjoy coading.. 🙂

Regards, Jay Doshi

Populate Current Loggedin User in People Picker

In one of my project we need populate current logged in user in People Picker by default. I have implemented below code to do it.

Add 1.7.2.jquery.min.js and jquery.SPServices-2014.02.min.js file in the master page or page level.

 
$(document).ready(function() { 
 ExecuteOrDelayUntilScriptLoaded(loadCurrentUser, "sp.js"); 
});

function loadCurrentUser() { 
 var userName = $().SPServices.SPGetCurrentUser({ fieldName: "UserName", debug: false});
 $('h3:contains("PeoplePickerFieldName")').closest('tr').find('div[title="People Picker"]').html(userName);
 $('img[title="Check Names"]').trigger('click'); 
} 

** Replace “PeoplePickerFieldName” with your people picker field name.

** Replace “userName” with your desired user’s user name to add other user in peoplepicker.

Let me know if you face any challenges.

Happy Coding.. 🙂

Regards, Jay Doshi

SP2013: How to Update static SharePoint Text in SharePoint Ribbon

Hello All,

Today I’m going to explain to update static text available in SharePoint top left corner ribbon text. By default it’s “SharePoint”. Now if you update that text you just need to execute below three line in Powershell command to update that text.

Default Text:

SharePointRibbon

$webApp = Get-SPWebApplication http://technology-khabar:2015
$webApp.SuiteBarBrandingElementHtml = "Welcome to Technology Khabar"
$webApp.Update()

After executing above code in PowerShell:

Untitled

How to get list of running worker process using command prompt

In SharePoint, if you want to debug your code then you need to attached W3WP worker process in Visual Studio to start debugging. Generally, we are attaching all the worker process. By doing this all the SharePoint services goes in the debugging mode and your process takes more execution time then it generally takes. To avoid this we have to attached only worker process (W3WP) which is associated with our application.

To attach worker process we need to navigate Tools Menus > Attach Process or we can use short cut command i.e. Ctrl + P. It will open new window in which all the process are listed and we will find the w3wp process and attach all that process to start the debugging.

To find which w3wp worker process is associated with our application, we need to go to IIS Manager which is very long process and other one is using Command Prompt.

  • Find associate process using IIS Manager

1. Open IIS Manager
2. Click on Worker Processes as displayed in below image.
Untitled
3. It will display your application name as well as Process ID. By the use of Process ID you can attach only 1 process to debug your code.

ListofWorkerProcess

In above process after every deployment you need to close the current Worker Process window and again open it to get it refresh so that it’s time consuming and hectic process.

  • Find associate process using Command Prompt

1. Open command prompt with Run as Administrator
2. Navigate to C:\Windows\System32\Inetsrv
3. C:\Windows\System32\Inetsrv> appcmd list wp to get all worker process along with Application Pool name. You will get result as below image.
CMD_WorkerProcess

This is very simpler method to get Process ID of your application while developing SharePoint custom code.

Enjoy 🙂 Happy Coading..:)

How to add custom control (delegate control) in SharePoint 2013 Masterpage(.html version)

Hi Floks,

Today I am going to talk regarding delegate control which is mostly used to insert SharePoint control in simple html pages. SharePoint contains many delegate control in it’s default master-page. Some of them are as listed below:

  1. AdditionalPageHead
  2. GlobalSiteLink0
  3. GlobalSiteLink1
  4. GlobalSiteLink2
  5. PublishingConsole
  6. QuickLaunchDataSource
  7. SmallSearchInputBox
  8. TopNavigationDataSource

You can customize this control as well as you can create you own delegate control by following below steaps:

  • Create Blank SharePoint blank solution in Visual Studio 2012

Blank Solution for Delegate Control

  • Add Visual Web-part in the solution.

AddVisualWebpartinBlankSolution

  • Open Elements.xml file and do following changes.
    • Do comment in Module tag and add below code in Elements.xml file
    • You can modify the the attribute value as per your requirements.
    • ID: This is control ID which is used to refer in the MasterPage
    • Sequence: Sequence of the Control
    • Control Src: ASCX file path which contains design of your control
<Control Id="CustomTopNavigation"
 Sequence="23"
 ControlSrc="~/_CONTROLTEMPLATES/15/MyCustomTopNavigation/TopNavigationUserCont rol.ascx" />
    • After modifying the Elemetns.xml file your xml file looks like below image.sdfElements.xml
    • Deploy your solution on SharePoint Site.
    • Activate your solution Feature from the Site Settings.
    • Now Add below tag in you html file/master page (.html) version
    • Replace ControlID value as per ID value specified in Elements.xml file
<!--MS:<SharePoint:DelegateControl runat="server" ControlId="CustomTopNavigation" Id="topNavigationDelegate"/>-->
    • Save your master page and publish as major version and verify the page which inherited from that Master page you can see your control on that page.

Thanks..! Happy Coading..:)

Clear SharePoint Designer Cache

Hi Floks,

Today I am going to explain how to clear cache of SharePoint Designer. By clearing SharePoint Designer Cache following things of SharePoint Designer will be wiped out.

  1. Site history which you open in SharePoint Designer in the past
  2. Credentials which you stored in SharePoint site
  3. Site folders which will be created while opening site in SharePoint Designer

Steps to clear SharePoint Designer Cache

  • Open Run

run

  • Open below listed path & Remove everything from the folder
    • %USERPROFILE%\AppData\Local\Microsoft\WebsiteCache
    • %APPDATA%\Microsoft\Web Server Extensions\Cache\

 

Now open SharePoint Designer, you can see all the history of we application which you opened in SharePoint Designer will be erased.

 

 

SharePoint URL shortcuts / URL of Pages which can be used for SharePoint Administrator

Below is the list of pages & their paths which can be accessed from URL :

Below listed URL’s works for SharePoint 2010 for SharePoint 2013 please add /15/after /_layouts.

  1. Add web parts to any page: /append ?PageView=Shared&ToolPaneView=2
  2. Create New Site Content: /_layouts/create.aspx
  3. Create New Site: /_layouts/NewsbWeb.aspx
  4. List Template Gallery: /_catalogs/lt/Forms/AllItems.aspx
  5. Master Page Gallery: /_catalogs/masterpage/Forms/AllItems.aspx
  6. Manage your Alerts: /_layouts/SubEdit.aspx
  7. Create New Alert: /_layouts/SubChoos.aspx
  8. Manage Site Collection Administrators: /_layouts/mngsiteadmin.aspx
  9. Manage Sites and Workspaces: /_layouts/mngsubwebs.aspx
  10. Manage People: /_layouts/people.aspx
  11. Manage User Permissions: /_layouts/user.aspx
  12. Modify Navigation: /_layouts/AreaNavigationSettings.aspx
  13. Modify Site Navigation: /_layouts/SiteNavigationSettings.aspx
  14. Recycle Bin: /_layouts/AdminRecycleBin.aspx
  15. Site Directory: _layouts/SiteDirectorySettings.aspx
  16. Save Site as Template: /_layouts/savetmpl.aspx
  17. Site Settings page: /_layouts/settings.aspx
  18. Create New Web Part Page: /_layouts/spcf.aspx
  19. Site Template Gallery: /_catalogs/wt/Forms/Common.aspx
  20. Site Column Gallery: /_layouts/mngfield.aspx
  21. Site Content Types: /_layouts/mngctype.aspx
  22. Site Content and Structure Manager: /_layouts/sitemanager.aspx
  23. Site Usage Summary: /_layouts/SpUsageWeb.aspx
  24. User Alerts: /_layouts/sitesubs.aspx
  25. View All Site Content: /_layouts/viewlsts.aspx
  26. Web Part Gallery: /_catalogs/wp/Forms/AllItems.aspx
  27. Web part maintenance mode: /append ?contents=1 to the URL of the page
  28. Open the page in Edit Mode – In Address bar, Type: “javascript:MSOLayout_ToggleLayoutMode();” or  “javascript:MSOTlPn_ShowToolPane(’2′);” in the Address bar
  29. Add Web Parts Pane: ?ToolPaneView=2
  30. Display all content types of sites: /_layouts/mcontent.aspx
  31. Sign as different User: /_layouts/closeConnection.aspx?loginasanotheruser=true

Save SharePoint Publishing site as Template

Hello Floks,

In one of our project, we need to save template of Publishing site. Microsoft restrict saving SP2013 Publishing sites as Template(more info).

Earlier version of SharePoint (Below than 2013) supports SharePoint does not support Save Site as Template option with the Publishing features turned on. The supported method to create templates for publishing sites is to use a site definition template and using a feature XML.

If you want to save publishing sites as templates there is a workaround. Since its forbidden there is no “Save site as a Template”  link in “Site Settings” page of publishing site. But you can get access to that page by using following URL:

/_layouts/savetmpl.aspx

But, this workaround can work on earlier version of SharePoint, in SP2013 this URL will work perfectly only for sites that have publishing features not activated. For publishing sites you get an error like

saving publishing sites as template is not allowed.

To allow this features work perfectly you need to do either of following steps:

Using PowerShell Script

$web=Get-SPWeb http://sharepointsiteurl[/subsite]
$web.AllProperties["SaveSiteAsTemplateEnabled"] = "true"
$web.Update()

Using SharePoint Designer

Open publishing site in SharePoint Designer click on File Menu from Top Navigation.

SharePointDesigner_SavePublisingSiteAsTemplate

Double Click or Click on Modify button once you select SaveSiteAsTemplateEnabled option.

 SharePointDesigner_PublishingSiteSaveAsTemplate

By default value is false update it as True and click on OK button and then Apply Button and again click on OK button of parent window.

SharePointDesigner_SaveSiteAsTemplate

Now you can access following page for Saving Publishing site As Template by using following URL:

http://publishing_siteURL/_layouts/savetmpl.aspx. 

Enjoy..:) 🙂 🙂