Category Archives: Technology

Webinar on 10/19/2011 at 2pm Eastern – Using SharePoint Designer in the ‘Real World’

This is a good opportunity to get free webinar by someone like Asif Rehmani. Following is the detail of the event as received.

See more at http://bytebeats.com/2011/10/19/webinar-on-10192011-at-2pm-eastern-using-sharepoint-designer-in-the-real-world/

Advertisements

SharePoint Automation – Power Shell Scripts

Hi,

How often I think about PowerShell Scripts while working on SharePoint 2007 and deploying solutions using Stsadm. Though, it worked well for me, but never got control as promissed by the powershell scripts.

Recently, I got chance to start working and ext exploring my experiences with PowerShell Scripts for deployment of SharePoint 2010 solution and doing a lot with Microsoft .Net object model siting outside Visual Studio and working in colorful Power Shell Snap In 🙂

Today, I’m gonna share a piece of work that we (SharePoint developers) needs to deal with almost in every SharePoint project, and that’s the deployment of SharePoint Solutions. You may find the contents of this post on google, but I tried to keep things simple and planned.

First of all, for those who are new to Power Shall, you may be wondering about the Commands that you can use with power shell. I use a better way to keep them with me, try the following command in Power Shell to dump all available SharePoint commands in a text file.

Get-Command -module Microsoft.SharePoint.PowerShell > textfilename.txt

Once You have all the commands, its easy for you to go and explore commands based on your requirements, I would say the Get-help is really helpful here 🙂

Now let’s play with Power shell and deploy our Solution files for the SharePoint Farm.

Lets take the case where we have some solution files, and we want to write a script that will Add and deploy solution files to specified Farm or Web.
To make it clean and dynamic I use a xml Configuration file for deployment.

<ProjectName>
<Solutions>
<Solution Name=”Usman.SP.Projects.Utilities.wsp” Path=”C:\Users\afzalu\PS_Scripts\Installer\Usman.SP.Projects.Utilities.wsp” CASPolicies=”false” GACDeployment=”true”>    </Solution>
<Solution Name=”Usman.SP.Projects.Branding.wsp” Path=”C:\Users\afzalu\PS_Scripts\Installer\Usman.SP.Projects.Branding.wsp” CASPolicies=”false” GACDeployment=”true”>    </Solution>
<Solution Name=”Usman.SP.Projects.Core.wsp” Path=”C:\Users\afzalu\PS_Scripts\Installer\Usman.SP.Projects.Core.wsp” CASPolicies=”false” GACDeployment=”true”>    </Solution>
<Solution Name=”Usman.SP.Projects.Pages.wsp” Path=”C:\Users\afzalu\PS_Scripts\Installer\Usman.SP.Projects.Pages.wsp” CASPolicies=”false” GACDeployment=”true”>    </Solution>
<Solution Name=”Usman.SP.Projects.RequestHandling.wsp” Path=”C:\Users\afzalu\PS_Scripts\Installer\Usman.SP.Projects.RequestHandling.wsp” CASPolicies=”false” GACDeployment=”true”>    </Solution>
<Solution Name=”Usman.SP.Projects.WebStructure.wsp” Path=”C:\Users\afzalu\PS_Scripts\Installer\Usman.SP.Projects.WebStructure.wsp” CASPolicies=”false” GACDeployment=”true”>    </Solution>
<Solution Name=”Usman.SP.Projects.Presentation.wsp” Path=”C:\Users\afzalu\PS_Scripts\Installer\Usman.SP.Projects.Presentation.wsp” CASPolicies=”false” GACDeployment=”true”>
<WebApplications>
</WebApplications>
</Solution>
<Solution Name=”Usman.SP.Projects.Sites.wsp” Path=”C:\Users\afzalu\PS_Scripts\Installer\Usman.SP.Projects.Sites.wsp” CASPolicies=”false” GACDeployment=”true”>
<WebApplications>
</WebApplications>
<Solution>
</Solutions>

</ProjectName>

For Now, I just take an example where I need to deploy the solution, but ofcourse with this design you can also do feature activation and other webapplication chnages (we will do that in some other post).

Now let’s see how easily we can add a Power Shell Script to add these solution to specific WebApplication or Farm

# add SharePoint Powershell snapin
add-PSSnapin Microsoft.Sharepoint.powershell
write-host “———————————————————-” -foregroundcolor Green
write-host “Deploying Soultions” -foregroundcolor Green

if($args){

# Getting web.Config File

$configFile = $args[0];

if ([string]::IsNullOrEmpty($configFile)) { return }

[xml]$solutionsConfig = Get-Content $configFile

if ($solutionsConfig -eq $null) { return }

$solutionsConfig.DLW.Solutions.Solution | ForEach-Object{
[string]$path = $_.Path
[bool]$gac = [bool]::Parse($_.GACDeployment)
[bool]$cas = [bool]::Parse($_.CASPolicies)
$webApps = $_.WebApplications.WebApplication

#Add the solution

$spAdminServiceName = “SPAdminV4”
[string]$name = Split-Path -Path $path -Leaf
$solution = Get-SPSolution $name -ErrorAction SilentlyContinue
Write-Host “Adding solution $name…”
$solution = Add-SPSolution $path

#Deploy the solution

if (!$solution.ContainsWebApplicationResource) {
Write-Host “Deploying solution $name to the Farm…”
$solution | Install-SPSolution -GACDeployment:$gac -CASPolicies:$cas -Confirm:$false
}
else {
if ($webApps -eq $null -or $webApps.Length -eq 0) {
Write-Warning “The solution $name contains web application resources but no web applications were specified to deploy to.”
return
}
$webApps | ForEach-Object {
Write-Host “Deploying solution $name to $_…”
$solution | Install-SPSolution -GACDeployment:$gac -CASPolicies:$cas -WebApplication $_ -Confirm:$false
}
}
# Restarting the Service
Stop-Service -Name $spAdminServiceName
Start-SPAdminJob -Verbose
Start-Service -Name $spAdminServiceName

#Block until we’re sure the solution is deployed.

do { Start-Sleep 2 } while (!((Get-SPSolution $name).Deployed))
} #End of $solutionsConfig.Solutions.Solution | ForEach-Object
}
write-host “Solutions Deployed Successfully” -foregroundcolor Green

write-host “———————————————————–” -foregroundcolor Green

Sorry for Formating, but it takes too much time so I prefer sharing things rather than spending lots of time on formating.
Once you run the above code you will see a very informative Power Shell Window, that will show you all the deployment setps in a friendly way so your deployement team can really enjoy the deployment.
You can use the below code to uninstall and delete the solution files using the same XML file

# add SharePoint Powershell snapin

add-PSSnapin Microsoft.Sharepoint.powershell

write-host “———————————————————-” -foregroundcolor Green

write-host “Deleting Soultions” -foregroundcolor Green

if($args){

# Getting web.Config File

$configFile = $args[0];

if ([string]::IsNullOrEmpty($configFile)) { return }

[xml]$solutionsConfig = Get-Content $configFile

if ($solutionsConfig -eq $null) { return }

$solutionsConfig.DLW.Solutions.Solution | ForEach-Object{

[string]$name = $_.Name

$spAdminServiceName = “SPAdminV4”

$solution = Get-SPSolution $name

# Un-Install Solutions

if($solution.Deployed){

if (!$solution.ContainsWebApplicationResource) {

Write-Host “Un-Installing solution $name from the Farm…”

$solution | UnInstall-SPSolution -Confirm:$false

}

else{

Write-Host “Un-Installing solution $name …”

$solution | UnInstall-SPSolution -AllWebApplications:$true -Confirm:$false

}

Stop-Service -Name $spAdminServiceName

Start-SPAdminJob -Verbose

Start-Service -Name $spAdminServiceName

#Block until we’re sure the solution is deployed.

do { Start-Sleep 2 } while (((Get-SPSolution $name).Deployed))

}

} #End of $solutionsConfig.Solutions.Solution | ForEach-Object

# Remove Solutions

$solutionsConfig.DLW.Solutions.Solution | ForEach-Object{

if(!$solution.Deployed){

[string]$name = $_.Name

Write-Host “Getting uninstall solution $name…” -foregroundcolor YELLOW

$unInstallSolution = Get-SPSolution $name

$unInstallSolution | Remove-SPSolution -Confirm:$false

Write-Host “Solutoin $name… Removed” -foregroundcolor YELLOW

}

}

}

write-host “Solutions Deleted Successfully” -foregroundcolor Green

write-host “———————————————————–” -foregroundcolor Green

Activate Site Directory Site Template in SharePoint 2010

If you are wondering about the “Site Directory Sit Template” in SharePoint 2010, then follow this blog post to use this feature onto your Share Point Server.

Actually, this feature is made Hidden by Intentionality for upgrade purpose from Share Point Server 2003 to 2010, and you need to make this feature visible and than activate for your specific web site.

Follow these steps to get rid of Hidden Directory Site Template Feature.

1. Open C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\1033\XML

2. Open webtempsps.xml for Eidt

3. Find section for “Site Directory” and change Hidden value

<Configuration ID="0" Title=”Site Directory” Type=”0″ Hidden=”FALSE” ImageUrl=”/_layouts/1033/images/template_site_dir.png” Description=”A site for listing and categorizing important sites in your organization. It includes different views for categorized sites, top sites, and a site map.” DisplayCategory=”Enterprise” VisibilityFeatureDependency=”5F3B0127-2F1D-4cfd-8DD2-85AD1FB00BFC”>

4. After that open command prompt and browse to
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN

5. Activate the feature ” SharePoint Server Publishing Infrastructure” onto your site (if not activated earlier)

6. Run following commaned:
stsadm.exe -o activatefeature -id 5F3B0127-2F1D-4cfd-8DD2-85AD1FB00BFC –url http://yoursite

After these steps, go to your site and Create a new site using Site Directory Site Template, it is there now :-).

Useful Information, Rate It.

Microsoft Second Shot is going to Expire

Get a second chance to pass your Microsoft Certification exam — free offer!

In the real world, you might need more than one chance at certification. With Second Shot, if you do not pass any IT professional, developer, or project manager certification exam on your first try, you can retake the exam without an additional cost.

Offer ends on June 30, 2009

Register for Second Shot and take advantage of our Career Assist Package—which means you can get any Microsoft E-Learning collection for just US$35.

Note Offer ends on June 30, 2009
Sign up for the Second Shot offer today

You have until June 30, 2009, to register, obtain an exam voucher, complete your first exam, retake your exam (if you did not pass on your first attempt), and complete any Microsoft E-Learning collections that you purchased.

When you register for this offer, you receive one free retake for each paid exam that you take and do not pass.

Register for Second Shot and obtain your US$35 Microsoft E-Learning collection

1. Register for Second Shot.
2. On the Thank You page that you receive, click the link to the Prometric Web site. You will receive a Second Shot voucher number and an e-learning promotion code.

Use your Second Shot voucher

Go to the Prometric Web site, call center, or test center. Use your Second Shot voucher number and schedule and pay for your initial exam.

Go to the Prometric Web site or visit the call center* or test center (Prometric.com)

Take your exam.

If you do not pass, return to the Prometric Web site or visit the call center or test center and use the same voucher number for your free retake exam.

Return to the Prometric Web site or visit the call center* or test center (Prometric.com)

Note: You must wait one day after taking your initial exam before you can register for your retake exam. This time is required to enter test results into the system.

qualify for this Second Shot offer?
Any Microsoft Learning IT professional, developer, or Microsoft Dynamics exam qualifies for this offer.

C# 3.0 Language Features

While Talking about .Net Framework, there are lots of many new things in every version, but I normally keep an eye on mostly used features from the perspective of re usability and easy of Code.

While Exploring, I crossed through some really usable features of .Net 3.0 & 3.5, and for the discussion here I would be covering Automatic Properties, Object Initiation, Extraction Methods, and Automatic Type Casting.

Automatic Properties

Normally, In every sort of project, specifically in every class most the time is eaten by the writing the class members and their setter and getter (properties or Indexers). Although, many third party tools like Visual Assist come up with the power of .Net Extensibility ( I will be writing some useful tips about it Soon), and easy the developer by provider Intellisense to a greater extend, but what If I tell you something built in .Net framework without spending any extra money for any third party Add In. Following is one of my Code Snip that I will use to explain the power and re usability of Automatic Properties.
I’m Omitting any required using statements to make it simpler and shorter.

namespace MyBlogApplication
{
public class PersonClass
{
//Person Class’s Properties
private String _name;
public System.String Name
{
get { return _name; }
set { _name = value; }
}

private String _addess;
public System.String Addess
{
get { return _addess; }
set { _addess = value; }
}

private String _personId;
public System.String PersonId
{
get { return _personId; }
set { _personId = value; }
}
}
}

Although the above code may be generated using the Reflector tools of .net, but it still requires me to write Class members and then reflect them as Public Properties, and of course it requires more lines of code then the one I wrote in .Net c# 3.5 as below

namespace MyBlogApplication
{
public class PersonClass
{
//Person Class’s Properties
public String Name { get; set; }
public String _addess { get; set; }
public String _personId { get; set; }
}
}

What i did just wrote “prop” (this is also available in .net 2.0), and press tab twice, so what I came with is the above snip, now what I need to do is just to give name to my property, and compiler will automatically generate the data member and deals with adding and retrieving from memory.

It’s not a rocket science, but imagine if you have more than 20 properties per class and for each one you have to create and manipulate data members, it’s a hell of coding job, but the above technique reduces and manages you code with beauty.

In the above code, you may put your properties as Read-Only Or Write-Only as follows

//Person Class’s Properties
public int Name { get; set; }
public int _addess { private get; set; } //Write-Only
public int _personId { get; } //Read-Only

Happy Coding with .Net 3.5 🙂