Wednesday, 19 November 2014

delete data from lists using power shell script in SharePoint

delete data from lists using power shell script

write-host "This will delete data, type YES to continue"
$retval = read-host
if ($retval -ne "YES")
{
    write-host "exiting - you did not type yes" -foregroundcolor green
    exit
}
write-host "continuing"

$web = get-spweb http://ggn-sp10:5555/
$list = $web.lists | where {$_.title -eq "ComplianceDetails"}
Write-host "List $($list.title) has $($list.items.count) entries"
$items = $list.items
foreach ($item in $items)
{
    Write-host "  Say Goodbye to $($item.id)" -foregroundcolor red
    $list.getitembyid($Item.id).Delete()
}

Sunday, 27 July 2014

Hiding SharePoint Ribbon Control from users

Hiding SharePoint Ribbon Control from users

Add this to the head section on master page.

<style type="text/css">
div#s4-ribbonrow {
display:none;
}
</style>

<Sharepoint:SPSecurityTrimmedControl runat="server"
Permissions="AddAndCustomizePages">
<style type="text/css">
div#s4-ribbonrow {
display:block;
}
</style>
</Sharepoint:SPSecurityTrimmedControl>



This should hide the ribbon control.

Thursday, 20 March 2014

Get the size of folder and Get Number Of Files In Folder in SharePoint


1. This method is used to get the size of folder in SharePoint


        private static long GetFolderSize(SPFolder folder)
        {
            long folderSize = 0;
            foreach (SPFile file in folder.Files)
            {
                folderSize += file.Length;
            }
            foreach (SPFolder subfolder in folder.SubFolders)
            {
                folderSize += GetFolderSize(subfolder);
            }
            return folderSize;
        }

2. This method is used to Get Number Of Files In Folder in SharePoint

        private static int GetNumberOfFilesInFolder(SPFolder folder)
        {
            int folderNum = 0;
            foreach (SPFile file in folder.Files)
            {
                folderNum += 1;
            }
            foreach (SPFolder subfolder in folder.SubFolders)
            {
                folderNum += GetNumberOfFilesInFolder(subfolder);
            }
            return folderNum;
        }

Tuesday, 28 January 2014

Show the loading message like (Please wait, Item is being launched for all active Employees .....) when click on button




<asp:Button runat="server" ID="btnLaunch" Text="Launch" Width="120px" OnClick="btnLaunch_Click" ValidationGroup="LaunchFields" CssClass="btnwidth" OnClientClick="OpenLoadingAlert();" />




<script type="text/javascript">
    function OpenLoadingAlert() {
        Page_ClientValidate();
        if (Page_IsValid) {
            SP.UI.ModalDialog.showWaitScreenWithNoClose('Loading...', 'Please wait, Item is being launched for all active Employees ..... ', 60, 270);
        }
    }
</script>