Monday 30 November 2015

Wednesday 25 November 2015

C# create GUID

            Console.WriteLine(@"System.Guid.NewGuid().ToString() = " + System.Guid.NewGuid().ToString());
            Console.WriteLine(@"System.Guid.NewGuid().ToString(""N"") = " + System.Guid.NewGuid().ToString("N"));
            Console.WriteLine(@"System.Guid.NewGuid().ToString(""D"") = " + System.Guid.NewGuid().ToString("D"));
            Console.WriteLine(@"System.Guid.NewGuid().ToString(""B"") = " + System.Guid.NewGuid().ToString("B"));
            Console.WriteLine(@"System.Guid.NewGuid().ToString(""P"") = " + System.Guid.NewGuid().ToString("P"));

Tuesday 24 November 2015

Remove “Restricted User” in SQL Server

Remove “Restricted User” in SQL Server
---------------------------------------------------------------
 
Use DatabaseName
ALTER DATABASE DatabaseName SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
ALTER DATABASE DatabaseName SET MULTI_USER
GO

Thursday 12 November 2015

sql multiple inner joins to same table



CREATE TABLE Table1
([weddingtable] int, [tableseat] int, [tableseatid] int, [name] varchar(4),
    [Created] int,[Modified] int)
;

INSERT INTO Table1
([weddingtable], [tableseat], [tableseatid], [name],[Created],[Modified[)
VALUES
(001, 001, 001001, 'bob',1,2),
(001, 002, 001002, 'joe',2,3),
(001, 003, 001003, 'dan',2,2),
(002, 001, 002001, 'mark',3,1)
;

CREATE TABLE Table2
([weddingtable] int, [tableseat] int, [meal] varchar(7))
;

INSERT INTO Table2
([weddingtable], [tableseat], [meal])
VALUES
(001, 001, 'chicken'),
(001, 002, 'steak'),
(001, 003, 'salmon'),
(002, 001, 'steak')
;
 
 CREATE TABLE usert
([userID] int,  [userName] varchar(7))
;
                                                                         
INSERT INTO usert
([userID], [userName])
VALUES
(1, 'A'),
(2, 'B'),
(3, 'C')
;
       
-----------------------
--Query

select * from Table1 t1
inner join usertable u
on t1.cre=u.userID
inner join usertable u1
on t1.Mod=u1.userID                                                                   

Tuesday 10 November 2015

Programmatically adjusting the "toolbar type of a ListViewWebPart using Powershell script"

I have a requirement to hide new item or edit list in SharePoint list



$powershellSnapin = “Microsoft.Sharepoint.Powershell”
if ((Get-PSSnapin -Name $powershellSnapin -ErrorAction SilentlyContinue) -eq $null )
{
Add-PsSnapin $powershellSnapin
}

try
    {
        $web= Get-SPWeb "url"  #url
       $webpartmanager = $web.GetLimitedWebPartManager("/Lists/1Contracts/AllItems.aspx", [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared) #Get the webpart manager class

        for($i=0;$i -lt $webpartmanager.WebParts.Count;$i++)  
            {
                if($webpartmanager.WebParts[$i].title -eq "1Contracts")   #list title
                    {  
                        $wp=$webpartmanager.WebParts[$i]; 
                        #$wp.ChromeType="TitleAndBorder"; #If you want to change ChromeType,Uncomment #.  
                        
                        $wp.View.Toolbar = "AllItems" #Getting view
                        [xml]$x = $wp.XmlDefinition
                        $x.View.Toolbar.Type = "None" # or Standard, Full, Freeform #Toolbar types
                        $wp.View.SetViewXml($x.view.OuterXml)
                        $wp.View.Update()

                        $webpartmanager.SaveChanges($wp);  

                        break; 
                    }
    
            }
 
       $web.Dispose(); 
  }
  catch
    {
        Write-Host  Error  :  $_.exception
    }


Wednesday 4 November 2015

SQL ROW_NUMBER OVER AND PARTITION BY

Table Name: myTable
Columns:

-->roll_no
-->classId
-->location

SQL Statements

--Get the count of rows based on columns

  SELECT *, ROW_NUMBER()OVER(PARTITION BY roll_no  ORDER BY subject DESC) rowCnt
    FROM myTable order by rowCnt desc
 
--Get the count of rows based on columns using where clause

 SELECT *, ROW_NUMBER()OVER(PARTITION BY roll_no  ORDER BY subject DESC) rowCnt
    FROM myTable
    where myTable.roll_no='1001'
 
--Query sub query data based on where clause  

    SELECT rid FROM(
 SELECT *, ROW_NUMBER()OVER(PARTITION BY roll_no  ORDER BY subject DESC) rowCnt
    FROM myTable
    where myTable.roll_no='1001'
)X WHERE classId= 7 and upper(location) != 'USA' and rowCnt = 1

Tuesday 3 November 2015

Create ListView using SharePoint PowerShell script



#Passing My Site Url
param($serverUrl)

#Begin arguments validation

if($serverUrl -eq $null)
{
$argErr = $true
}

if($argErr)
{
Write-Host
Write-Host -ForegroundColor Red "One or more parameters missing or invalid. Please see the usage and give the proper parameters"
Write-Host
Write-Host "Usage: Creating List View  messages"
Write-Host
   
    exit
}

try

{

$web = Get-SPWeb -Identity $serverUrl

Write-host
Write-host  "------Getting  List-----"
Write-host

$list = $web.Lists["Demo Ticket"]


Write-host
Write-host  "------  Making Query -----"
Write-host

$ViewName =  "Demoview" #My View Name
     
        $Query = "<Where><Eq><FieldRef Name='AssignedTo'/><Value Type='Integer'><UserID /></Value></Eq></Where>"

Write-host
Write-host  "------Getting Fields for View-----"
Write-host

$fields = $list.Views["All Items"].ViewFields.ToStringCollection()

$viewRowLimit = 50   #Row Limit
$viewPaged = $true #Paged property
$viewDefaultView = $false   #DefaultView property

Write-host
Write-host  "------Adding View  to list-----"
Write-host

$result = $list.Views.Add($ViewName, $fields, $Query, $viewRowLimit, $viewPaged, $viewDefaultView)

Write-host
Write-host  "---- Updating list -----"
Write-host

$list.Update()

Write-host
Write-host  "----- Successfully Added View to  List -Demo View  -----"
Write-host

$web.Update()
}
catch [System.SystemException]
{
  write-host "Execution stopped due to: "+$_.Message -foregroundcolor Red
}