Posts

Showing posts from 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() {   ...

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             ...

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...

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($roleDefin...

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...

SharePoint: Add existing field to content type using PowerShell

This Power S hell Script is used for add existing site field or column to a content type:     cls Remove-PSSnapin Microsoft.SharePoint. Powershell -ErrorAction SilentlyContinue Add-PSSnapin Microsoft.SharePoint. Powershell $site = Get-SPSite -Identity " Your Site Url " $web = $site.RootWeb $ct=$web.ContentTypes[" ContentType "]; $fieldAdd=$web.Fields[" Field Name "] $fieldLink=New-Object Microsoft.SharePoint. SPFieldLink($fieldAdd) $ct.FieldLinks.Add($fieldLink) ; $ct.Update() $web.Dispose() $site.Dispose()    

ASP.NET : Dirty Form(data save confirmation on unload form using jquery)

Image
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <!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 runat="server">     <title></title>     <script type="text/javascript" src="jquery-1.3.2.min.js"></script>     <script type="text/javascript">         var initialdata = "nothing";         $(document).ready(function () {             initialdata = $('#Panel1 *').serialize();         });         function CheckFormDirty() {             var frmData = $('#Panel1 *').serialize(); ...

ERROR:Operation is not valid due to the current state of the object.

ERROR:Operation is not valid due to the current state of the object.  When you send more than 1000 control within a single post request then this type of error will occur Solution:  Add an appsetting in WebConfig:  <appSetting>  <add key="aspnet:MaxHttpCollectionKeys" value="20001"/>  //in the value field put the number of controls you want to send in post request for example-20001.  </appSetting>

Drop Down Under Repeater Using VB.NET

Bind Drop Down with Reapter:  <asp:Repeater runat="server" ID="rp_DropDown" OnItemDataBound="rp_DropDown_ItemDataBound">    <HeaderTemplate>         <div>                 DropDown         </div>     </HeaderTemplate>    <ItemTemplate>         <div>               <asp:DropDownList ID="DropDown1" runat="server"                OnSelectedIndexChanged="DropDown1Changed" AutoPostBack="true">                 </asp:DropDownList>          </div>     ...

Suppress StyleCop SA1600

    Local Suppression: [SuppressMessage("Microsoft.StyleCop.CSharp.DocumentationRules",  "SA1600:ElementsMustBeDocumented", Justification = "Reviewed.  Suppression is OK here.")] for local suppression you must use namespace  using System.Diagnostics.CodeAnalysis;   OR you can also use   [System.Diagnostics.CodeAnalysis.SuppressMessage ("Microsoft.StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented")]  Example:   using System.Diagnostics.CodeAnalysis;   [SuppressMessage("Microsoft.StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "Reviewed. Suppression is OK here.")] protected void Button1_Click(object sender, EventArgs e)   {   } [SuppressMessage("Microsoft.StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "Reviewed. Suppression is OK here.")]  protected v...

Timesheet using GridView(also logging using enterprise library)

Image
 Default.aspx: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %> <!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>     <style type="text/css">         .style1         {             width: 100%;         }         .style2         {             width: 50%;          ...