Posts

Showing posts from December, 2012

ASP.NET Change Control Style When Validation Fails

Image
CSS Style:  <style type="text/css">         body         {             font-family: Arial;             font-size: 10pt;         }         .ErrorControl         {             // Put control style here which you want after validation fails             background-color: #FBE3E4;             border: solid 1px Red;         }     </style> Java Script: <script type="text/javascript">         function WebForm_OnSubmit() {             if (typeof (ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) {                 for (var i in Page_Validators) {                     try {                         var control = document.getElementById(Page_Validators[i].controltovalidate);                         if (!Page_Validators[i].isvalid) {                             control.className = "ErrorControl";                         } else {                             control.className = "";                       

PowerShell Pause Script Execution

Some Times we feel need to pause execution of a PowerShell Script, in that case we use: Start-Sleep -s 30 above code pause script for 30 seconds for milliseconds:   Start-Sleep -m 1000

SharePoint 2010 Customize Error Page

in layouts create an application page(sp2010), name it as ErroronPage.aspx. and write your code inside it.   PowerShell Script: cls  Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue  Add-PSSnapin Microsoft.SharePoint.Powershell  $webApp = Get-SPWebApplication " http://sp2010:47940/ " $webApp.UpdateMappedPage([Microsoft.SharePoint.Administration.SPWebApplication+SPCustomPage]:: Error ,"/_layouts/ErrorOnPage.aspx") $webApp.Update() we can also use this script for some other usage:   AccessDenied  Confirmation  Error  Login  RequestAccess  Signout  WebDeleted Replace these with Error in "$webApp.UpdateMappedPage..." line.

SharePoint Redirection from Pop Up

Image
Redirect to any page from SharePoint PopUp:   on continue button click event code:             string script = string.Format("window.frameElement.navigateParent('{0}');",        SPHttpUtility.EcmaScriptStringLiteralEncode(" Home.aspx "));             Page.ClientScript.RegisterStartupScript(Page.GetType(), "redirectToPage", script, true);                 After this it'll redirect at "Home" page.

PowerShell: SharePoint Check In All Files

In SharePoint Site Document Library for check in all files or documents using PowerShell:   cls Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue Add-PSSnapin Microsoft.SharePoint.Powershell function CheckInDocument([string]$url) { $spWeb = Get-SPWeb $url $SPBaseTypeDocumentLibrary = [Microsoft.SharePoint.SPBaseType]::DocumentLibrary $lists = $spWeb.GetListsOfType($SPBaseTypeDocumentLibrary); foreach ($list in $lists) {            if ($list.Hidden -eq $False -and $list.BaseTemplate.ToString() -eq "1302")     {                Write-Host Checking in documents from Library : $list.Title         $getFolder = $spWeb.GetFolder($list.Title)         $files  = $list.CheckedOutFiles                write-host "Total Checked Out Files : " $files.Count                $list.CheckedOutFiles | Where { $_.CheckOutStatus -ne "None" } |         ForEach {                $_.TakeOverCheckOut();                      $docItem = $list.GetItemById($

Sql Server : Change Login Password or Forgot Password

Image
when you forgot your sql server password or want to generate new password, in that case follow some steps: 1. Start Command Prompt 2. write:          osql -E -S .\SQLEXPRESS(Server Name)                    exec sp_password @new=' changeme ', @loginame=' sa '          go          alter login sa enable          go          exit

jquery: Adjust Table Column's Width

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server">     <title></title>     <!-- jQuery -->     <script type="text/javascript" charset="utf8" src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js"></script>     <!-- DataTables -->     <script type="text/javascript" charset="utf8" src="https://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.8.2/jquery.dataTables.min.js"></script>     <script type="text/javascript">         $(document).ready(function () {             /* start Datatable */             var oTable = $('#example').dataTable({                 "bAutoWidth": false,                 "aoColumnDefs": [             

SharePoint: Create site Group with Permission Using PowerShell

 cls  Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue  Add-PSSnapin Microsoft.SharePoint.Powershell  function ADDGroup([string]$GroupName,[string]$OwnerName,[string]$MemberName,[string]$Description, [string]$SiteUrl,[string]$PermissionLevel) {   $Site= Get-SPSite -Identity $SiteUrl  $SPWeb = $Site.RootWeb  if ($SPWeb.SiteGroups[$GroupName] -ne $null){   Write-Host "Group "$GroupName" already exists!"   Break;  } else  {   $owner = $SPWeb | Get-SPUser $OwnerName   if ($MemberName -ne "") {  $member = $SPWeb | Get-SPUser $MemberName }   $SPWeb.SiteGroups.Add($GroupName, $owner, $member, $Description)   $SPGroup = $SPWeb.SiteGroups[$GroupName]   $roleDefinition = $SPWeb.Site.RootWeb.RoleDefinitions[$PermissionLevel]   $roleAssigment = new-object Microsoft.SharePoint.SPRoleAssignment($SPGroup)   $roleAssigment.RoleDefinitionBindings.Add($roleDefinition)   $SPWeb.RoleAssignments.Add($roleAssigment)   $SPWeb.U

SharePoint: Create Site Collection Using PowerShell

cls Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue Add-PSSnapin Microsoft.SharePoint.Powershell $siteName = " SiteName " $port = 80 $hostHeader = "public. SiteName .com" $url = "http://public. SiteName .com" $appPoolName = " SiteName Public" $managedAccount = " managed Account " $dbServer = " DB Server Name " $dbName = " DB Name " $allowAnonymous = $true $authenticationMethod = "NTLM" $ssl = $false $template = Get-SPWebTemplate "STS#0" # Please dont change line below as script need to run under the account of logged in user $siteAdmin = $env:userdomain + "\" + $env:username; #Remove-SPWebApplication -identity $url -Confirm New-SPWebApplication -Name $siteName -Port $port -HostHeader $hostHeader -URL $url -ApplicationPool $appPoolName -ApplicationPoolAccount (Get-SPManagedAccount “$managedAccount”) -DatabaseName $dbName -DatabaseServer $dbServer -AllowAnon

SharePoint: Create Group using PowerShell

Power Shell Script: cls Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue Add-PSSnapin Microsoft.SharePoint.Powershell $groupsXML = [xml] (Get-Content ("Group.XML")) $Site= Get-SPSite -Identity $groupsXML.GRoups.Site; $GroupName=$groupsXML.GRoups.GroupName; $OwnerName=$groupsXML.GRoups.OwnerName; $MemberName=$groupsXML.GRoups.MemberName; $Description=$groupsXML.GRoups.Description;  $SPWeb = $Site.RootWeb;  if ($SPWeb.SiteGroups[$GroupName] -ne $null){   Write-Host "Group "$GroupName" already exists!"   Break;  } else  {   $owner = $SPWeb | Get-SPUser $OwnerName   if ($MemberName -ne "") {  $member = $SPWeb | Get-SPUser $MemberName }   $SPWeb.SiteGroups.Add($GroupName, $owner, $member, $Description)   $SPGroup = $SPWeb.SiteGroups[$GroupName]   $SPWeb.RoleAssignments.Add($SPGroup)  } $SPWeb.Dispose() return $ErrMessage XML File: <Groups> <Site> Enter Your Site Url </Site> <GroupName> Ente