BAT SCRIPT TO OPEN SQL SERVER PORTS IN THE FIREWALL

rem ******************code start******************************
 
@echo off 
sc config MpsSvc start= demand 
sc start MpsSvc
 
echo. *** OPENING SQL SERVER PORTS IN THE FIREWALL *** 
echo. source Mohamed Riyaz.
echo. 
echo. Note for Named Instances – SQL mirroring – Dynamic Ports and the firewall 
echo. see http://msdn.microsoft.com/en-us/library/cc646023(v=SQL.100).aspx#BKMK_programs 
echo. You will need to open firewall ports for your mirroring endpoints and possibly dynamic ports 
echo. 
echo. 
echo. Opening SQL Server TCP 1433 
netsh advfirewall firewall add rule name=”SQL Server (TCP 1432)” dir=in action=allow protocol=TCP localport=1433 profile=domain 
echo. 
echo. Opening SQL Admin Connection TCP 1434 
netsh advfirewall firewall add rule name=”SQL Admin Connection (TCP 1434)” dir=in action=allow protocol=TCP localport=1434 profile=domain 
echo. 
echo. Opening SQL Service Broker TCP 4022 
netsh advfirewall firewall add rule name=”SQL Service Broker (TCP 4022)” dir=in action=allow protocol=TCP localport=4022 profile=domain 
echo. 
echo. Port 135 
netsh advfirewall firewall add rule name=”SQL Debugger/RPC (TCP 135)” dir=in action=allow protocol=TCP localport=135 profile=domain 
echo. 
echo. Opening SQL Browser UDP 1434 
netsh advfirewall firewall add rule name=”SQL Browser (UDP 1434)” dir=in action=allow protocol=UDP localport=1434 profile=domain 
echo. 
echo. Opening Analysis Services TCP 2383 
netsh advfirewall firewall add rule name=”Analysis Services (TCP 2383)” dir=in action=allow protocol=TCP localport=2383 profile=domain 
echo. 
echo. Opening SQL Browser TCP 2382 
netsh advfirewall firewall add rule name=”SQL Browser (TCP 2382)” dir=in action=allow protocol=TCP localport=2382 profile=domain 
echo. 
echo. ***Done ***
 
sc stop MpsSvc 
sc config MpsSvc start= disabled
 
rem ******************code end******************************

PowerShell script to file browse, change file attribute, restore SharePoint site backup

Here is a nice little utility (written using PowerShell script) which I use to restore a site backup time to time.

Some features of this script are:

1. Displays a file browse dialog to select a file (see – Invoke-FileBrowser)

2. Removes the read-only attribute on the file (see – Remove-Readonly), this is required as the backup file is stored in TFS.

3. Restore a given backup file, without asking for confirmation (see – Restore-SPBackup)

——————————————————————————————————————————

$ErrorActionPreference = "Stop"

Add-PSSnapin Microsoft.SharePoint.PowerShell -EA 0

# Example:
# $file = Invoke-FileBrowser -Title "Select a file" -Directory "D:\backups" -Filter "Powershell Scripts|(*.ps1)"
function Invoke-FileBrowser
{
      param([string]$Title,[string]$Directory,[string]$Filter="All Files (*.*)|*.*")
      [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
      $FileBrowser = New-Object System.Windows.Forms.OpenFileDialog
      $FileBrowser.InitialDirectory = $Directory
      $FileBrowser.Filter = $Filter
      $FileBrowser.Title = $Title
      $Show = $FileBrowser.ShowDialog()
      If ($Show -eq "OK")
      {
            Return $FileBrowser.FileName
      }
      Else
      {
            Write-Error "Restore cancelled by user."
      }
}

# Example:
# Remove-Readonly -FilePath "D:\backups\filename.txt"
function Remove-Readonly
{
    param([string]$FilePath)
    #Remove read-only attribute, otherwise access denied error.
    Set-ItemProperty -Path $FilePath -name IsReadOnly -value $false
}

# Example:
# Restore-SPBackup -FilePath "D:\backups\backupfile.bak"
function Restore-SPBackup
{
    param([string]$BackupFilePath, [string]$WebUrl)
    #Restore the backup without asking for confirmation.
    Restore-SPSite -Identity $WebUrl -Path $BackupFilePath -Confirm:$false
}

$backupLocation = "C:\mywork\scm\JRCP.Internet\JRCP.Internet\JRCP Data Structures\Site Backups"
$SiteUrl = "http://sp2010riyaz:4040"

$file = Invoke-FileBrowser -Title "Browse" -Directory $backupLocation -Filter "All Files (*.*)|*.*"
Remove-Readonly -FilePath $file
Restore-SPBackup -BackupFilePath $file -WebUrl $SiteUrl
--------------------------------------------------------------------

Wait for more useful utilities…

 

Adding XsltListViewWebPart to a Homepage (landing-page) in Site Definition and Setting the Web Part Display Properties

Read It

Have you ever tried add a XsltListViewWebPart to display a list view (e.g. “My Project Tasks” or “My Issues”) to the default landing page of your site and unable to change the title of the webpart, frame type etc. as the code differs from that of a standard web part?

You may have tried this by declaratively copying the XML from an existing page after a customization but still no luck.

Let’s Fix

The following declaration shows how you can use the “ListViewWebPart” to accomplish this (I presume, most of you’ll familiar with the view declaration):

<View List="$Resources:BflResource,ldiv_lists_Folder;/$Resources:BflResource,ldiv_projectTask_Folder;" MobileView="TRUE" MobileDefaultView="TRUE" Type="HTML" Url="$Resources:BflResource,ldiv_lists_Folder;/$Resources:BflResource,ldiv_projectTask_Folder;/MyItems.aspx" BaseViewID="2" ImageUrl="/_layouts/images/issuelst.png" WebPartZoneID="Right" WebPartOrder="1">
          <XslLink Default="TRUE">main.xsl</XslLink>
          <RowLimit Paged="TRUE">15</RowLimit>
          <Toolbar Type="Standard" />
         <ViewFields>
            <FieldRef Name="LinkTitle" />
            <FieldRef Name="StartDate" />
            <FieldRef Name="DueDate" />
            <FieldRef Name="PercentComplete" />
            <FieldRef Name="Status" />
            <FieldRef Name="Priority" />
            <FieldRef Name="Predecessors" />
          </ViewFields>
          <Query>
            <Where>
              <Eq>
                <FieldRef Name="AssignedTo" />
                <Value Type="Integer">
                  <UserID />
                </Value>
              </Eq>
            </Where>
            <OrderBy>
              <FieldRef Name="Status" />
              <FieldRef Name="Priority" />
            </OrderBy>
          </Query>
        <![CDATA[
        <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2"&gt;
          <Assembly>Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c
          </Assembly>        
       <TypeName>Microsoft.SharePoint.WebPartPages.ListViewWebPart</TypeName>
          <Title>$Resources:core,My_Tasks;</Title>        
          <FrameState>Normal</FrameState>
          <AllowRemove>true</AllowRemove>
          <AllowZoneChange>true</AllowZoneChange>
          <AllowMinimize>true</AllowMinimize>
          <AllowConnect>true</AllowConnect>
          <AllowEdit>true</AllowEdit>
          <AllowHide>true</AllowHide>
          <IsVisible>true</IsVisible>
          <MissingAssembly>$Resources:core,ImportErrorMessage;</MissingAssembly>
        </WebPart>
        ]]>
      </View>

Finally

Related references:

http://stackoverflow.com/questions/4156014/add-an-xsltlistviewwebpart-to-a-site-defintion-homepage
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webpartpages.xsltlistviewwebpart.aspx
http://stefan-stanev-sharepoint-blog.blogspot.com/2010/06/sharepoint-2010-binaryserializedwebpart.html

Applying v4.MasterPage as a Search Center MasterPage

Read It

Last week when I was working on a client project I had a requirement of applying v4.masterpage into Search Center as the search center was disconnected from rest of the site collection for its global navigation. So during my search for a solution I came across this useful link “Converting a Custom SharePoint 2010 Master Page into a Search Center Master Page” posted by Randi Drisgill. This blog was simply listing the steps required to achieve what I wanted. So I went ahead and applied the steps mentioned in there. Everything went well and thanks to Randi.

Once after completing the steps mentioned in there, I started performing some basic tests and oops, I came across two bickering issues:

  1. The search box was found to be left aligned which was different to the alignment set in OOB.
  2. When page loads an additional ribbon row gets displayed momentarily and disappeared.

Let’s Fix

So I had to work on finding a solution for both the issues before releasing the solution.

  1. Fixing Issues# 1: I had to remove the style attribute (in the masterpage) margin:inherit as shown below:

    .srch-sb-results4 {
               margin: inherit;
               padding-left: 20px;
    }

  2. Fixing Issue# 2: A <div> tag should be introduced with style set to display:none surrounding the  “notificationArea” div.

<div style="display:none">
       <div id="notificationArea">
       </div>
       <asp:ContentPlaceHolder ID="SPNavigation" runat="server">
                     <SharePoint:DelegateControl runat="server" ControlId="PublishingConsole" Id="PublishingConsoleDelegate">
                     </SharePoint:DelegateControl>
       </asp:ContentPlaceHolder>
</div>

That’s all you need in addition to what Randi Drisgill already provided.

FinallySearch Center