Blog Home  Home |  Breeze Home RSS 2.0 Atom 1.0 CDF  
SCAREY Sharepoint Blog
Shannon - Breeze Training
# Monday, July 05, 2010

Recently I have been doing some work with the K2 guys, and have been exploring using consuming Smart Objects within custom SharePoint web parts/application pages etc.

One of the problems with deploying your webpart to the different environments (ie dev, stg, prod etc) is where do we specify the K2 host server name? Well it seems we havea few options

  1. web.config file under the app settings
  2. hard code into the c# code
  3. property bag in SharePoint (my favourite)

Using the property bag on the root web of the site collection allows us to be able to specify different K2 servers for the different environments using the SPWeb.Current.Context.Site.RootWeb.Properties[“K2HostServer”];

Please see below for the SharePoint 2007 powershell script to add the K2 server property (please note this must be run on the SharePoint server.

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

$k2hostserver = "servername"

$sharepointserver = "spservername"

$site = new-Object Microsoft.SharePoint.SPSite($sharepointserver)

$spweb = $site.OpenWeb("/")

if($spweb.Properties.ContainsKey("K2HostServer") -eq $False ) { $spweb.Properties.Add("K2HostServer", $k2hostserver)} else { $spweb.Properties["K2HostServer"] = $k2hostserver}

$spweb.Properties.Update()

$spweb.Dispose()

Monday, July 05, 2010 10:20:30 AM (AUS Eastern Standard Time, UTC+10:00)  #    Comments [1]    | 
# Monday, November 23, 2009

One place I often see new developers get stuck when developing with the SharePoint Object Model is trying to get information from a document library or list field

The place they get stuck is they write

string smyField = SPListItem.Fields[“myField”].ToString();

This will return the name of the column/field NOT the value within it

The trick is to write it like this

string smyField = SPListItem[“myField”].ToString();

Monday, November 23, 2009 11:33:11 AM (AUS Eastern Daylight Time, UTC+11:00)  #    Comments [0]    | 
# Tuesday, November 17, 2009

For many years, well since MOSS 2007 was released, I have always wanted to use the Content Query Web Part to display the results of multiple calendars.

I know there are many different projects to do this, free ones on Codeplex such as the Planet Wilson Colour Calendar and the SharePoint Enhanced Calendar by ArtfulBits  as well as the Bamboo Solutions SharePoint Calendar Plus Web Part which you can pay for. These are all great projects and solutions,

BUT

All I want is the plain old simple content query web part to work as it always has and display a calendar view. Users know how to use it and this way I don’t have to train them on a new web part.

So what I did was create a calendar view for the content query web part (or ContentByQueryWebPart). There is one change that was made from what you might expect, and that is I appended which site the calendar is from at the start of the calendar title

Please feel free to download and use this Web Part in you SharePoint environment

n.b If the calendar is not showing all the events make sure that you have increased the Item Limit under Presentation in the Web Part Properties

ContentByQueryCalendar.wsp (39.83 KB)

ContentByQueryCalendar.zip (38.31 KB)

Tuesday, November 17, 2009 12:51:12 PM (AUS Eastern Daylight Time, UTC+11:00)  #    Comments [0]    | 

I was recently working on a piece of code that required merging 2 DataTables based on 2 columns, however the table that I was merging the results into, I need not add the row if the columns matched. After searching around the net for a while and not really finding anything very useful I decided to write my own.

Essentially we get 2 DataTable’s and loop through the first one. If we find the where column1 and column2 in the first table row match column1 and column2 in the second DataTable row the we delete the row in the second DataTable. Finally we merge the2 tables with t duplicates removed.

The magic essentially happens with DataTable.Select and DataTable.Merge

This code is C# .NET

//tables that will be merged
DataTable table1 = new DataTable();
DataTable table2 = new DataTable(); //duplicates will be removed
 
//columns used to store what is found in the row's column
string column1 = string.Empty; 
string column2 = string.Empty;
 
// loop through the rows in the first table and if
// the columns are found on an item in the second
//table then remove it
foreach (DataRow row in table1.Rows)
{
    //set the column variables to what is in the 
    //current row
    column1 = row["column 1 Name"].ToString();
    column2 = row["column 2 Name"].ToString();
 
    //get an array of each of the rows that match
    //the columns in the current row
    DataRow[] duplicateRows = table2.Select("Section = '" + 
        column1 + "' AND Subsection = '" + column2 + "'");
    
    //loop through and remove each of the rows in the 
    //table that are duplicates 
    foreach (DataRow duplicateRow in duplicateRows)
        table2.Rows.Remove(duplicateRow);
}
 
//merge the tables so that we now have 1
table1.Merge(table2);
Tuesday, November 17, 2009 11:09:53 AM (AUS Eastern Daylight Time, UTC+11:00)  #    Comments [0]    | 
# Saturday, October 31, 2009

Today I presented SharePoint 2010 at the Australian Office Developer Conference and needed Internet access. I finally bit the bullet and bought a wireless modem. I grabbed the Virgin mobile one from some dodgy phone shop and did a remote desktop session back to the server at the office. I am surprised to say that it worked almost seamlessly for the entire demo.

Sitting at the airport I just did a speed test and was pleased to see 1.39Mb/s upload and 4.6 Mb/s download.

I am interested to see if I get this kind of network access everywhere

Saturday, October 31, 2009 6:30:44 PM (AUS Eastern Daylight Time, UTC+11:00)  #    Comments [0]    | 
# Friday, October 30, 2009

I have been doing a bit of work recently with the SPSiteData Query in SharePoint. Dealing with CAML with this isn't the easiest especially when it only returns a subset of information that it should from a site.

As I was developing my queries I was using the fantastic U2u CAML Query Builder and getting my queries to work perfectly. What became really annoying is that they didnt work in my custom web parts. After many hours of banging my head against the wall, I found a KB Article

Search results are incomplete when you use a CAML query that uses the SPSiteDataQuery class to search content on a SharePoint Server site or on a Windows SharePoint Services 3.0 site

Reading this title I thought WOW and then realised that the update was fined in the Infrastructure Update, I am running SP2. After bashing my head against the wall a few times, I realised that the way I installed SharePoint was with SP@ slipstream media. After an uninstall of SharePoint and then a SP1 install followed by a Infrastructure update install and finally SP2 install the queries started to work

If you're having trouble with your queries that should be working then make sure that you installed the infrastructure update before SP2

Friday, October 30, 2009 5:37:07 PM (AUS Eastern Daylight Time, UTC+11:00)  #    Comments [0]    | 
# Tuesday, April 14, 2009

WOW!!!!! SharePoint designer is free. http://blogs.msdn.com/sharepoint/archive/2009/04/02/sharepoint-designer-available-as-a-free-download.aspx I think that MS has really hit the nail on the head with this decision :) In many classes that I run, teaching many students, Decision Makers, Designers, End Users etc I have found that this is a huge stumbling block from so many people. My business bought SharePoint but don't want to pay for the designer is something I hear way too often. Good job Microsoft, this will certainly encourage much more SharePoint customisations

Tuesday, April 14, 2009 12:47:19 PM (AUS Eastern Standard Time, UTC+10:00)  #    Comments [0]    | 
# Saturday, April 11, 2009

Hi,

I have had the task of having to start and stop virtual machines in Windows Server 2008 Core without the use of Hyper-V Manager or VMM.

It is possible to start and stop the machines if you only have access to the command prompt through the use of WMI.

I have hacked together a script file that can start/stop/list what virtual machines are available and their current state

Instructions

download the file  VMControl.vbs (2.77 KB)

run VMControl.vbs with the following arguments

eg. "VMControl.vbs /list"

"/list" = list all VM's and their state
"/start virtualMachineName" = starts the the virtual machine
"/stop virtualMachineName" = stops the virtual machine
"/startAll" = starts all virtual machines on the host providing there is enough resources
"/stopAll" = stops all virtual machines on the host
"/help" = help information

Here is the code for it

*nb you may have to run this with admin privileges

Option Explicit 
 
'Setup the variables
Dim WMIService
Dim VMList
Dim Hostname
Dim VMName
Dim VMAction
Dim compareType
Dim HOST
Dim VM
Dim VMStatus
Dim AllVMs
 
'Used to get all machines or just one
compareType = "="
 
'gets and sets the host name
Set HOST = WScript.CreateObject("WScript.Network")
 
'Get instance of 'virtualization' WMI service on the local computer
Set WMIService = GetObject("winmgmts:\\.\root\virtualization") 
 
'Get the arguments from the user input and go to the appropriate sub
if wscript.Arguments.count > 0 then
    Select case WScript.Arguments.Item(0)
        case "/start"
            VMName = WScript.Arguments.Item(1)
            VMAction = 2
            compareType = "="
            modifyVM
        case "/stop"
            VMName = WScript.Arguments.Item(1)
            VMAction = 3
            compareType = "="
            modifyVM
        case "/startAll"
            VMName = HOST.ComputerName
            VMAction = 2
            compareType = "!="
            modifyVM
        case "/stopAll"
            VMName = HOST.ComputerName
            VMAction = 3
            compareType = "!="
            modifyVM
        case "/list"
            VMName = HOST.ComputerName
            compareType = "!="
            listVMs
        case "?","/?","-?","help","Help","/help","/Help"
            helpMsg
        case else
            helpMsg
    end select
else 
    helpMsg
end if
 
'Message to display when incorrect input or recived help switch
sub helpMsg
    AllVMs = "usage VMControl.vbs" 
& VBCr & VBCr & "/start <VM Name> - Starts the Virtual Machine" 
& VBCr & "/stop <VM Name> - Stops the Virtual Machine" 
& VBCr & "/startAll - Start all Virtual Machines" 
& VBCr & "/stopAll - Stop All Virtual Machines" 
& VBCr & "/list - List All Virtual Machines" 
end sub
 
'used to turn the VM on or off or saved
sub modifyVM
    Set VMList = WMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem 
WHERE ElementName" & compareType & "'" & VMName &"'") 
 
    For Each VM In VMList
        VM.RequestStateChange(VMAction)          
        select case VMAction
            case 3 VMStatus = "stopped"
            case 2 VMStatus = "running"
            case 32769 VMStatus = "saved"
        end select
            AllVMs = VM.ElementName & " is " & VMStatus
    next
end sub
 
'used to get and display the VM's
sub listVMs
    Set VMList = WMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem 
WHERE ElementName" & compareType & "'" & VMName &"'") 
 
    For Each VM In VMList
        select case VM.EnabledState
            case 3 VMStatus = "stopped"
            case 2 VMStatus = "running"
            case 32769 VMStatus = "saved"
        end select
        AllVMs = AllVMs + VM.ElementName & " is " & VMStatus  & VBCr
    next
end sub
 
'Display a message of what happened or a help message
wscript.echo AllVMs

VMControl.vbs (2.77 KB)

Saturday, April 11, 2009 4:14:41 PM (AUS Eastern Standard Time, UTC+10:00)  #    Comments [1]    | 
# Monday, April 28, 2008

So today the question was posed,

What happens if you stop the Central Administration or Web service in SharePoint in a small farm/single server?

Well maybe you should start them again. How you ask?

Use the stsadm command to do so. Simply run stsadm from the 12 hive (by default C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\bin) with the following options

For the Web Service
stsadm.exe -o provisionservice -action start -servicetype Microsoft.SharePoint.Administration.SPWebService

For central administration
stsadm.exe -o provisionservice -action start -servicetype Microsoft.SharePoint.Administration.SPWebService -servicename WSS_Administration

Monday, April 28, 2008 10:04:22 PM (AUS Eastern Standard Time, UTC+10:00)  #    Comments [4]    | 
Copyright © 2010 Breeze Training. All rights reserved.