Posts

Showing posts from 2013

SharePoint 2010 Retract and Remove Projects using Powershell Script

Sometimes you need to retract and remove multiple wsp. If you will do it manually then its a time taking process. So here is a power shell script that will help you surely. clear Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue Add-PSSnapin Microsoft.SharePoint.Powershell function RetractAndRemoveSolution {param ($SolutionPackageName, $DeployedGlobally)   $solution = Get-SPSolution | where-object {$_.Name -eq $SolutionPackageName}     # check to see if solution package has been installed      if ($solution -ne $null)    {          if($solution.Deployed -eq $true)         {          if( $DeployedGlobally -eq $true)      {     Uninstall-SPSolution -Identity $SolutionPackageName -Local -Confirm:$False       ...

.Net Object Comparison Using Generics

Image
Some time we need to compare two objects or properties or entities. For ex. we are going for save data to data base so we need to compare our old data and new data. If any changes are there then we will go for save otherwise we don't need. Here is a simple example of Entity comparison using generics. For demo purpose i am putting only one label on my screen, that will tell us, Input objects are similiar or not. .aspx <asp:Label ID="lblResult" runat="server" Text="Label"></asp:Label> In code behind i have taken an Entity Class and create two objects of the same. On page load, Assigning different values to both. .aspx.cs   // Entity for Details         public class DetailsEntity         {             public string Name { get; set; }             public string Number { get; set; }         }  // Object Compare Generics Class ...

Telerik Rad Grid Sorting Not Working for Numeric String and Date String Columns

As i have posted my last blog post for sorting Telerik Rad Grid Sorting . That was a normal sorting but if you want to sort numeric string column or date string column in that case you would not get desired result. For example: Values are 5, 31, 22, 41, 76, 8, 6 When we click on column header for sorting then sorted values are 22, 31, 41, 5, 6, 76, 8  But expected result is 5, 6, 8, 22, 31, 41, 76 So for take over this problem follow below example : For example we will add a numeric string column and a date string column to my last blog post Telerik Rad Grid Sorting .  .aspx Code : <telerik:GridBoundColumn DataField="Date" HeaderText="Date" DataType="System.DateTime"   SortExpression="Date"></telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Number" HeaderText="Number" DataType="System.Int32"    SortExpression="Number"></telerik:GridBoundColumn> Also when you...

Telerik Rad Grid Sorting

If you are using Telerik Rad Grid and also need to sort column on column's header click than for your requirement below code will help you surely. .aspx Code : <telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="True" EnableViewState="false" AutoGenerateColumns="False" OnSortCommand="RadGrid1_SortCommand"  OnNeedDataSource="RadGrid1_NeedDataSource">  <SortingSettings EnableSkinSortStyles="true" />   <MasterTableView AllowNaturalSort="false" AllowSorting="True" AutoGenerateColumns="False">     <Columns>        <telerik:GridBoundColumn DataField="Name" HeaderText="Name"  SortExpression="Name">        </telerik:GridBoundColumn>        <telerik:GridBoundColumn DataField="Address" HeaderText="Address"  SortExpression="Address">        </telerik:GridBoundColumn...

Check Box inside Rad Grid 508 Compliance

Many times we used check box inside a grid like : <telerik:GridTemplateColumn UniqueName="ColoumnChk" HeaderText="Check Here">         <ItemTemplate>              <asp:CheckBox ID="chkNew" AutoPostBack="true" runat="server" Text="Abc" />          </ItemTemplate>  </telerik:GridTemplateColumn>  But some time we need to hide check box text like :  <telerik:GridTemplateColumn UniqueName="ColoumnChk" HeaderText="Check Here">         <ItemTemplate>              <asp:CheckBox ID="chkNew" AutoPostBack="true" runat="server" Text="" />          </ItemTemplate>  </telerik:GridTemplateColumn> In this case an accessibility error(508 Compliance) will occur. So for treat this error we have to provide check box text and hide that ...

RadDatePicker Invalid Date Alert Box

There is no validator in .net that validate raddatepicker's invalid date. in this case we should use raddatepicker's client event on error. <telerik:RadDatePicker  runat="server" ID="rdpStartDate">            <DateInput runat="server">                <ClientEvents OnError=" ValidateDate " />            </DateInput>        </telerik:RadDatePicker> JavaScript function  ValidateDate (sender,args) {            var reason = args.get_reason();            if (reason === 1)             {                 alert("Invalid Date");            }     ...

PowerShell Copy File From One Location to Another

Here is a powershell script that copy files from one location to another in same computer/machine. $CurrentLocationandFileName = " C:\Users\Administrator\Desktop\New.txt " $DestinationLocation = " D:\NewFolder " copy $CurrentLocationandFileName -Destination $DestinationLocation

PowerShell Create Folder or Directory

Here is a powershell script that create a new folder or directory. $FolderPathandName =  " c:\Users\Administrator\Desktop\FolderName " [IO.Directory]::CreateDirectory( $FolderPathandName )

PowerShell Delete Folder or Directory If Exist

Here is a powershell script for delete folder if folder is exist at their location. $Folder=" c:\Users\Administrator\Desktop\NewFolder " If (Test-Path $Folder) { Remove-Item $Folder }

Required Field Validator for CheckBoxList

When you use asp check box list and want to apply required field validator then follow below example.   <asp:CheckBoxList ID = "chkDemoList" runat = "server" > <asp:ListItem Text = "India" Value = "IN" ></asp:ListItem> <asp:ListItem Text = "United States of Americs" Value = "USA" ></asp:ListItem> <asp:ListItem Text = "Japan" Value = "JP" ></asp:ListItem>   </asp:CheckBoxList> <asp:CustomValidator runat = "server" ID = "cv DemoList " ClientValidationFunction = "Validate DemoList " ErrorMessage = "Required Field" ></asp:CustomValidator> // javascript to add to your aspx page function Validate DemoList (source, args) { var chkListModules= document.getElementById (' <%= chkDemoList . ClientID %>'); var chkListinputs = chkListModules.getElementsByTagName("in...

RadGrid Row Select

If you want to select row in RadGrid then set some RadGrid properties like              <ClientSettings Selecting-AllowRowSelect="true" Selecting-EnableDragToSelectRows="false">              <MasterTableView DataKeyNames="ID"> If you want to select first row then use below code                if (RadGrid.Items.Count > 0)                 {                     RadGrid.MasterTableView.Items[0].Selected = true;                 } If you want to select any row on that basis of data key name then use below code         ...

SharePoint 2010 Consume SP List Data to Grid View

There is some data in your SPList and you want to show those list items in a grid view then follow below example. first of all create a visual webpart and put a grid view into that like: <asp:GridView ID="grdDocuments" runat="server" AutoGenerateColumns="false" > <Columns> <asp:BoundField DataField="ID" HeaderText="ID"></asp:BoundField> <asp:BoundField DataField="Name" HeaderText="Name"></asp:BoundField> </Columns> </asp:GridView> Now we have to do some code for bind data in this grid. void BindDocuments()         {             SPWeb mySite = SPContext.Current.Web;             SPList myList = mySite.Lists[" MyDocsLibName "];             SPListItemCollection items = myList.Items;             //Here we will make a datatable and we will put our document library data to the data table ...

SharePoint Reset Unique Permissions (Inherit Permissions) on a List/Library Using PowerShell

## CLEAR AND ADD SNAP IN ##    cls Remove-PSSnapin Microsoft.SharePoint. Powershell -ErrorAction SilentlyContinue Add-PSSnapin Microsoft.SharePoint. Powershell }      ## ASSIGN VARIABLE ##   $webUrl  =  $args [0]  $listName  =   $args [1]  $listInherits  =  $args [2]    # Varibale to hold document count   $count  = 0        ##  OPEN OBJECTS & RESTORE INHERITANCE ##      try  {       # Open the web and list objects        $web  = Get - SPWeb  $webUrl        $list  =  $web .Lists[ $listName ]         # If the list should inherit, reset the role inheritance     ...

C# generate random string of different length

If you want to generate random strings of different different lengths, than use below function. Here size is an input variable for length of string.      public static string RandomString( int size)       {             string builder = string .Empty;              Random random = new Random ();              char ch;              for ( int i = 0; i < size; i++)              {                  ch = Convert .ToChar( Convert .ToInt32( Math .Floor(26 * random.NextDouble() + 65)));                  builder +...

C# generate random numbers in a range

 If you want to generate a random nomber in a range than use below function. it has two inputs "min" -  enter min value of your range and "max" - enter max value of your range.  public static int RandomNumber( int min , int max )          {              Random random = new Random ();              return random.Next(min, max);          } Here in above function Random is a class. this is exist in .net framework by default. you should only use namespace "using System" for this.

SharePoint 2010 Enable Session State

If you trying to store data to session or using session in your user control, application page, webpart etc. then some time it may encounter an error below if session property not set to true in web.config. Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the..... first enable session state to true in web.config <pages enableSessionState="true" enableViewState="true" enableViewStateMac="true" validateRequest="false" pageParserFilterType="Microsoft.SharePoint.ApplicationRuntime.SPPageParserFilter, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" asyncTimeout="7"> second add name session to modules in web.config  <modules runAllManagedModulesForAllRequests="true"> ---- -...

Telerik Print Report Export to PDF

First create a telerik report or follow my previous post  http://himanshu214.blogspot.in/2013/01/telerik-create-report.html   For Print that report or Export to PDF Default.aspx: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %> <%@ Register Assembly="Telerik.Web.UI, Version=2012.3.1205.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4"     Namespace="Telerik.Web.UI" TagPrefix="telerik" %> <%@ Register Assembly="Telerik.ReportViewer.WebForms, Version=6.2.12.1017, Culture=neutral, PublicKeyToken=a9d7983dfcc261be"     Namespace="Telerik.ReportViewer.WebForms" TagPrefix="telerik" %> <!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"> <body>  ...

Telerik ToolTip

Image
.aspx code: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ToolTip.aspx.cs" Inherits="PopUp.ToolTip" %> <%@ Register Assembly="Telerik.Web.UI, Version=2012.3.1205.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4"     Namespace="Telerik.Web.UI" TagPrefix="telerik" %> <html> <body>     <form id="form1" runat="server">     <asp:ScriptManager ID="ScriptManager1" runat="server">     </asp:ScriptManager>     <div>         <telerik:RadToolTip ID="RadToolTip1" runat="server" Position="TopCenter"             Text="ToolTip for Help Image."             TargetControlID="HelpImg3">         </telerik:RadToolTip>     </div>     <p>...

Telerik Create Report

Image
Create Report: There are some steps to create telerik report 1. go to visual studio create a new project as ClassLibrary under Windows Template and name it as ClassLibrary1.  2. go to ClassLibrary1 add new item select DataSet under Data Template and name it as DataSet1.xsd   3. go to DataSet1 window and Create new Data Table name it as Data. 4. Add columns to this table like DataColumn1, DataColumn2, DataColumn3 and build the Project ClassLibrary1 5. go to ClassLibrary1 add new item and select Telerik Report under Reporting Template and nae it as Report1.cs. 6. When you add new report then one telerik report wizard will be open.   7. Click add new Data Source 8. Select Object Data Source and click ok  9. Select DataSet1 and Click Next >   10. Click Radio Button Choose a data source member and select DataSet1() and Click Finish >>| 11. Select objectDataSource1 and click Next > 12. Next >  14. Sel...