Blog Home  Home |  Breeze Home RSS 2.0 Atom 1.0 CDF  
SCAREY Sharepoint Blog - Tuesday, November 17, 2009
Shannon - Breeze Training
# 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]    | 
# Wednesday, April 23, 2008

So today I was trying to work out how to create a web part connection using pictures in one list and linking that to text in another list. Ohh and all this without having to create a custom web part!

First I tried adding a picture column to the first list, and creating the connection on various areas of the picture. No such luck.

Next I decided that I was going to have to write some code, but wanted to be able to get other people to do this as well without having to fire up Visual Studio, so I investigated a Form Web Part.

The way this works is that we upload our pictures into a library. We then need to configure the Form Web Part to use these pictures as Hyperlinks. Some JavaScript is then run to set a hidden text field to a predefined value based on the image clicked on, and finally the connection provides the data from the hidden field to a column in the other list.

Here is the code

<!-- Start JavaScript -->
<script type="text/javascript">
 
//Function to tell the page to set a hidden textbox (Resource Type) to value 
//"Applications" and then posting it to SharePoint. 
//The value in the textbox will be used to filter the 
//list that the web part is connected to
function application1()
{
document.getElementById("Resource Type").value = "Application";
_SFSUBMIT_;
}
function tool1()
{
document.getElementById("Resource Type").value = "Tools";
_SFSUBMIT_;
}
</script>
 
<!-- set up a hidden textbox that will be used to hold the --> 
<!-- filter data for the web par connection -->
<p><input name="Resource Type" id="Resource Type" type="hidden" /></p>
 
<!-- set up a hyperlink of a picture that when clicked on -->
<!-- will run the javascript to set the custom field type -->
<!-- for the web part connection -->
<a href="javascript:application1()">
<img alt="Applications" src="/applications.jpg" /></a><br />
<a href="javascript:tool1()"><img alt="Tools" src="/applications.jpg" /></a>

Wednesday, April 23, 2008 12:00:51 AM (AUS Eastern Standard Time, UTC+10:00)  #    Comments [0]    | 
# Thursday, July 19, 2007

Today I was playing around with CAML and CAML Query builder, when I wanted to call the current user, which was not in the tool, I found that <UserID/> is the correct syntax

Thursday, July 19, 2007 11:38:07 AM (AUS Eastern Standard Time, UTC+10:00)  #    Comments [0]    | 
Copyright © 2010 Breeze Training. All rights reserved.