BizTalk Utilities CV ,   Jobs ,   Code library
 
Go to the front page to continue learning about XML or select below:

Contents

ReBlogger Contents

Previous posts in XML

 
 
Page 7798 of 21350

What about PowerShell?

Blogger : Geekswithblogs.net
All posts : All posts by Geekswithblogs.net
Category : XML
Blogged date : 2007 Dec 13

More on MOSS...

In order to build our MOSS application we have decided to make the application as loosly-coupled from SharePoint as possible primarily because of the performance problems trying to develop on a Virtual Machine.  So, how do we do it most effectively?  With the help of some sound design patterns and a little PowerShell, it becomes pretty simple.  Let's begin with the design pattern.

First we need to create a standard ASP.NET website project. 

Then we need to create a "SolutionBuilder" project which is a standard Class Library project.

On the property window of each of the two projects we need to make the default namespace to be identical.  We'll try Chadster.SharePoint.

At this point neither project has a reference to each other.  Now on the web site we'll create a class called ChadsterBasePage.  Its implementation is pretty simple:

using System.Web.UI;

 

namespace Chadster.SharePoint

{

    public class ChadsterBasePage : Page

    {

        public ChadsterBasePage()

        {

            //

            // TODO: Add constructor logic here

            //

        }

    }

}

Now, on in the SolutionBuilder Project, we need to add references to Microsoft.SharePoint.dll and System.Web.dll and we need to create the same class as above:

using Microsoft.SharePoint.WebControls;

 

namespace Chadster.SharePoint

{

    public class ChadsterBasePage : LayoutsPageBase

    {

        public ChadsterBasePage()

        {

            //

            // TODO: Add constructor logic here

            //

        }

    }

}

The obvious difference is that our SolutionBuilder inherits LayoutsPageBase (so that we can deploy as an application page.)  In our base pages, we can now expose properties that could be exposed using the SharePoint API such as site title or site Id, etc.

Now, in the website project, we can create as many pages as we like all inheriting from our base page.  Here is where the magic of powershell comes in.  We can write a simple script to copy template files and *.cs files to appropriate locations within the "SolutionBuilder" project to be build into a dll.

In addition, the PowerShell script will also modify our manifest.xml file so that when we build the WSP file as described HERE.

The PowerShell Script looks like this:

$solutionBuilder = "C:\Safe\SolutionBuilder"

$12HiveLayouts = "$solutionBuilder\TEMPLATE\LAYOUTS"

$12HiveLayoutsGraphics = "$12HiveLayouts\[ProjectName]"

$manifestFile = "$solutionBuilder\manifest.xml"

$csFolder = "$solutionBuilder\[ProjectName]"

$asciiEncoding = "ascii"

 

Get-ChildItem  $csFolder | Foreach-Object { Remove-Item $_.FullName -force -recurse }

Get-ChildItem  $12HiveLayoutsGraphics | Foreach-Object { Remove-Item $_.FullName -force -recurse }

 

 

Get-ChildItem C:\Safe\Website\Graphics\*.cs | ForEach-Object { Copy-Item $_.FullName $csFolder }

 

Get-ChildItem C:\Safe\Website\*.ascx | ForEach-Object { Copy-Item $_.FullName $12HiveLayoutsGraphics -force }

Get-ChildItem C:\Safe\Website\*.aspx | ForEach-Object { Copy-Item $_.FullName $12HiveLayoutsGraphics -force }

 

[xml]$manifest = Get-Content $manifestFile

$templateFiles = $manifest.Solution.TemplateFiles

$templateFiles.RemoveAll()

 

Get-ChildItem $12HiveLayoutsGraphics | Foreach-Object {

      $templateFile = $manifest.CreateElement("TemplateFile")

      $templateFiles.AppendChild($templateFile)

      $templateFile.SetAttribute("Location", "LAYOUTS\[ProjectName]\$($_.Name)")

}

 

$manifest | Format-Xml  | Out-File $manifestFile -encoding $asciiEncoding

 

$manifestText = get-content $manifestFile

$manifestText -replace 'xmlns=" "',''  | set-content $manifestFile

 

 Enjoy!

 


Read comments or post a reply to : What about PowerShell?
Page 7798 of 21350

Newest posts
 

    Email TopXML