Ads

Saturday, 31 May 2014

PeopleEditor control to trigger CheckNames click on focusout event in clientside

For example in your aspx page having one PeopleEditor control .But you need to resolve the names in client side.
First you have to check whether the PeopleEditor control having any value or not.
This scenario we can use the _hiddenSpanData which is one of  the hidden input control for the PeopleEditor control .This control id will be like “PeopleEditor control id__hiddenSpanData”.It will be having the value which we entered in the PeopleEditor control.
If Editor control having value then trigger the CheckName anchor button. For this we can use _checkNames. This control id will be like “PeopleEditor control id_checkNames”.
Here is the sample code:
<%@ Register Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Namespace="Microsoft.SharePoint.WebControls" TagPrefix="cc1" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head2" runat="server">
<title>PeopleEditor Page</title>
<script type="text/javascript" language="javascript">
function TriggerCheckNameClick()
{
var pickerval = document.getElementById('<%=PplEditorCtrl.ClientID%>' + "_hiddenSpanData").value;
pickerval = pickerval.replace(/&nbsp;/gi, '');
if ((pickerval != null) && (pickerval != '') && (pickerval != ' ')) {
document.getElementById('<%=PplEditorCtrl.ClientID%>' + "_checkNames").click();
}
}
</script>
</head>
<body style="margin:0px; padding:0px">
<form id="form2" runat="server">
<div>
      <table width="100%">
         <tr>
              <td>
<cc1:PeopleEditor ID="PplEditorCtrl" MultiSelect="true" runat="server" SelectionSet="User" AllowEmpty="true" Width="500" onfocusout="TriggerCheckNameClick()"/>
</td>
       </tr>
   </table>
</div>
</form>
</body>
</html>

Delete sharepoint list item by power shell

1. Create new PowerShell (.ps1) file with below script using Notepad

$Url = "http://site-url:5000"
$ListName = "Sales 2013"
$Web = Get-SPWeb $Url
$List = $Web.lists[$ListName]

if($List -eq $null)
{    
  Write-Error "The List cannot be found";return
}

Write-Warning "Deleting all list items from $($ListName)"
$Items = $List.GetItems()
Write-Host "Total Items to be deleted : $($Items.count)"

if($Items.count -gt 0)
{
  $shell = new-object -comobject wscript.shell
  $result = $shell.popup("Total Item to be deleted : $($Items.count) `nDo   you want to continue?",0,"Alert",4+32)

if($result -eq "6")
{
foreach ($item in $Items)
{
  $itemId = $item.ID
  $List.GetItemById($itemId).Delete()
  Write-Host "Deleted list item with id $($itemId)"
}
}
}
$List.Update()
$Web.Dispose()


2. Replace values of parameters $Url and $ListName

3. Save file in server hard drive (Example: D:\PowerShell\Delete-List-Items.ps1)

4. Open "SharePoint 2010 Management Shell" with "Run as administrator"

5. Navigate to the folder where the script  file is stored
    (Example: cd D:\PowerShell)

6. Select file to be executed
    (Example: .\Delete-List-Items.ps1)

Modal Window Using JavaScript in SharePoint

2 ways to open SharePoint Modal Window using JavaScript:

1. Using the DialogOptions class.
var options = SP.UI.$create_DialogOptions();

options.title = "My Dialog Title";
options.width = 400;
options.height = 600;
options.url = "/_layouts/DialogPage.aspx";

SP.UI.ModalDialog.showModalDialog(options);

2. Using a generic object.
var options = {
    title: "My Dialog Title",
    width: 400,
    height: 600,
    url: "/_layouts/DialogPage.aspx" };

SP.UI.ModalDialog.showModalDialog(options);

Ref.: http://msdn.microsoft.com/en-us/library/ff410058(v=office.14).aspx

JavaScript In OnLoad Event Of Body SharePoint

many times we might require to call some functions on body onload event. As web part does not contain body tag we cannot use onload attribute of body tag.

To overcome this drawback, a developer can use an array i.e. _spBodyOnLoadFunctionNames
The only thing we need to do is to pass the function's name using .push method.

Example:
<script language="javascript">
_spBodyOnLoadFunctionNames.push("TestFunction");

function TestFunction() 

   alert("hello"); 

</script> 

We can use above script in master page, aspx page, content editor web part, visual web part as per the need.

Create link to Download a copy from a SharePoint Document Library

Generate a link using below format:
http://spsite/subsite/_layouts/download.aspx?SourceUrl=http://spsite/subsite/shared documents/fileName.docx
And use this URL in Anchor tag / window.open etc. as per the requirement.

Find the Site collection Size and all details

Open SharePoint 2010 Management Shell / Windows Command Prompt as administrator

Enter below command to access "stsadm.exe" and press enter
cd "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN"

Type below command and press enter
STSADM.exe -o enumsites -url "<Url of the web application>"
  Command will give output where you can see site collection details like:
a.   Url
b.   Ower
c.   Content Database
d.   Storage Used MB
e.   Storage Warning MB
5.   Modify the command with text file path to get output in text file
Example:
STSADM.exe -o enumsites -url "<Url of the web application>" > c:\SiteDetails.txt

Friday, 30 May 2014

Remove the Banner from InfoPath Form 2007

stsadm.exe -o setformserviceproperty -pn allowbranding -pv false

Take IIS backup in SharePoint Server

Step1: Start --> Administrative Tools-->IIS Manager
Step2: Right Click on Computer Name --> All Tasks--> Backup/Restore
Step3: Click on Create Backup
Step4: Name the Backup File and make the backup file password protected
Step5: Done!!
Step6: Check the Backup file in C:\WINDOWS\system32\inetsrv\MetaBack it will be in 2 names .
Step7: to restore them Click on Restore option

Ads