.comment-link {margin-left:.6em;}


Tuesday, November 30, 2004

Using anchors in CMS with the Telerik r.a.d. editor

Some customers switched to the Telerik r.a.d. editor for CMS because this placeholder has a lot more features than the standard CMS placeholders. Currently it's free if you have a valid CMS license.

But using anchors causes sometimes a lot of trouble. Instead of going to the anchor, the posting switches to edit-mode!
We did some searching and found
this page.
This behaviour is by design??? Strange, the placeholder doesn't have to store the URL of the page, just the anchor. So why does it point to the unpublished page? This looks more like a bug then a feature!

Here's some Javascript to replace the unpublished URL by the published URL for the anchors:

<script language="javascript">
var link = "";
var anchor = "";
var as = 0;
for (var i=0;i<window.document.links.length;i++) {
link = window.document.links(i).href;
as = link.indexOf("#");
if (as > -1) {
anchor = link.substring(as);
if (anchor.length > 1) {
window.document.links(i).href = "<%= ContentManagement.Publishing.CmsHttpContext.Current.Posting.URL%>" + anchor;

Selecting the right Area when using the Sharepoint Navigation control

In our CMS project we are using the Sharepoint Navigation control (and other SPS controls) in our CMS pages.
We created an area (i've called it kHSw in this example) in Sharepoint with the name of our CMS website, our pages our displayed in Sharepoint using the connector. But whenever we browse to our CMS-website (it still looks like you are in Sharepoint), the Home area is selected instead of the area we've created.
There seems no easy way to change this, so I wrote some Javascript to deselected Home and select our area in the navigation bar.

I've changed the line <div class="ms-phnav1wrapper ms-navframe">
in our HTML to <div class="ms-phnav1wrapper ms-navframe" name="Intranet_Navbar" id="Intranet_Navbar" >

Here's the Javascript (I know, it could have been a little shorter, but at least this should be readable):
<script language="javascript">
var Area = "kHSw";

//Part1 - Select kHSw
var HTML = Intranet_Navbar.innerHTML;
var OC = HTML.indexOf(">" + Area + "<");
var TD1 = HTML.lastIndexOf("<TD ", OC);
TD1 = HTML.lastIndexOf("<TD ", TD1 - 1);
var TD2 = HTML.indexOf("</TD>", OC);
TD2 = HTML.indexOf("</TD>", TD2 + 1);
var tempHTML = HTML.substr(TD1, TD2 - TD1);
var replacedHTML = tempHTML.replace("Ms-phnavmidl1", "Ms-phnavmidl0Sel");
replacedHTML = replacedHTML.replace("Ms-phnavmidc1", "Ms-phnavmidc0Sel");
replacedHTML = replacedHTML.replace("Ms-phnavmidr1", "Ms-phnavmidr0Sel");
HTML = HTML.replace(tempHTML, replacedHTML);

//Part2 - Deselect Home
OC = HTML.indexOf(">Home<");
TD1 = HTML.lastIndexOf("<TD ", OC);
TD1 = HTML.lastIndexOf("<TD ", TD1 - 1);
TD2 = HTML.indexOf("</TD>", OC);
TD2 = HTML.indexOf("</TD>", TD2 + 2);
tempHTML = HTML.substr(TD1, TD2 - TD1);
replacedHTML = tempHTML.replace("Ms-phnavmidl0Sel", "Ms-phnavmidl1");
replacedHTML = replacedHTML.replace("Ms-phnavmidc0Sel", "Ms-phnavmidl1");
HTML = HTML.replace(tempHTML, replacedHTML);

//Write the replaced HTML
Intranet_Navbar.innerHTML = HTML;

Sunday, November 28, 2004

Stop users from opening an Access application on the network

If you have an Access application and you want to force your users to copy it locally before using it (so multiple users can work on the same database on the same time), there's an easy way to stop them from running it over the network.

Create a module in your Access application and paste this code:
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

Private Const DRIVE_UNKNOWN = 0
Private Const DRIVE_NO_ROOT_DIR = 1
Private Const DRIVE_REMOVABLE = 2
Private Const DRIVE_FIXED = 3
Private Const DRIVE_REMOTE = 4
Private Const DRIVE_CDROM = 5
Private Const DRIVE_RAMDISK = 6

Public Function CheckDrive()
If GetDriveType(Left(CurrentProject.Path, 3)) <> DRIVE_FIXED Then
MsgBox "Please do not run this program from the network drive!"
End If
End Function

Now create a new Macro and call it AUTOEXEC (this macro will be automatically run when the application is opened). In the Action column you select RunCode(), on the bottom of the screen type the name of the function you want to execute, this is CheckDrive() in my example.

I know, there's an easy way to circumvent this 'protection', but most end-users don't know the 'secret-Access-key'. I'm not going to put it here, because this key is well-known to all developers ;-)

I included the other drive-types if case you want to check for an other type of drive.

And a little bonus:
If you want to check if a drive is a CD or DVD (with the GetDriveType()-API you'll get DRIVE_CDROM for both), you can use this little piece of code:

Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" (ByVal lpRootPathName As String, lpFreeBytesAvailableToCaller As Currency, lpTotalNumberOfBytes As Currency, lpTotalNumberOfFreeBytes As Currency) As Long

Private Function IsDriveADVD() as Boolean
Dim UserSpaceFree as Currency
Dim TotalUserSpace as Currency
Dim TotalFreeSpace As Currency

GetDiskFreeSpaceEx("E:\", UserSpaceFree, TotalUserSpace, TotalFreeSpace)

Return (TotalUserSpace > 1073741824)
End Function

If the total bytes on the disk (independant of the number of bytes used) is more than 1GB, we assume it's a DVD...

How do I stop My Documents window from opening at startup?

This is a question I received a while ago. After an upgrade to Windows XP SP2 the 'My Documents' folder always opened when Windows was started.
I ran msconfig, but couldn't find anything suspicious... After a while I found out there was something wrong with the 'userinit'-key in the registry.
The value of this key (HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\UserInit) was C:\WINDOWS\system32\userinit.exe,C:\WINDOWS\system32\userinit.exe.
Changing this key to only C:\WINDOWS\system32\userinit.exe solved the problem.

Thursday, November 25, 2004

Load a MDI-child by only passing the name

If you want your programmers to only write one line of code to load an MDI-child, you can use the code below to check if the form is already loaded. If not, the form will be created based on the name passed as parameter (this string is case-sensitive!). Put this code in your MDI-parent.

Create this function to see if a form is already loaded:
Private Function FormAlreadyLoaded(ByVal formName As String) As Form
For Each frm As Form In Me.MdiChildren
If frm.Name.ToUpper.Equals(formName.ToUpper) Then
Return frm
End If
Return Nothing
End Function

Add this function to load the form:
Private Sub LoadForm(ByVal formToLoad As String)
Dim frm As Form = FormAlreadyLoaded(formToLoad)
If frm Is Nothing Then
frm = DirectCast(Reflection.Assembly.GetExecutingAssembly.CreateInstance(Reflection.Assembly.GetExecutingAssembly.GetName.Name & "." & formToLoad), Form)
frm.MdiParent = Me
frm.Icon = Me.Icon
If frm.WindowState = FormWindowState.Minimized Then
frm.WindowState = FormWindowState.Normal
End If
End If

Now you can open a form named Form1 by typing LoadForm("Form1")...

Resizing the background picture of a MDI parent window

If you have a picture as background of your MDI, that picture is not resized when you resize your form. There seems no easy way (like a property) to accomplish this.

So I wrote a little piece of code that will create a new image starting from the original background image, but with the dimensions of the main form.

Declare a global variable for your form:
Private myBackground As Image

Add this code to the Resize-event of your form:
If myBackground Is Nothing Then
myBackground = Me.BackgroundImage
End If

If Me.ClientSize.Width = 0 Then Exit Sub 'Remark1

Dim bmp As New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height, Imaging.PixelFormat.Format24bppRgb) 'Remark2
Dim gr As Graphics = Graphics.FromImage(bmp)
gr.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
gr.DrawImage(myBackground, 0, 0, bmp.Width, bmp.Height)
Me.BackgroundImage = bmp

If you have a statusbar (called myStatus in this example) on the bottom of your form, alter the line marked with 'Remark1 to
If Me.ClientSize.Width = 0 OrElse Me.ClientSize.Height <= Me.myStatus.Height Then Exit Sub
and change the line marked with 'Remark2 to
Dim bmp As New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height - Me.myStatus.Height, Imaging.PixelFormat.Format24bppRgb)

Sunday, November 21, 2004

Local HTML files are blocked using Windows XP SP2

Due to the changes to the Local Machine Zone Security Settings in SP2 you might get this message when you are running a locally stored HTML-page:
To help protect your security, Internet Explorer has restricted this file from showing active content that could access your computer. Click here for options...

Instead of always clicking on the Information Bar and reloading the page, just add this line above the HTML-code:

<!-- saved from url=(0024)http://kHSw.blogspot.com -->

Tuesday, November 09, 2004

Dolmen jobevent

(Sorry, this one is only for the people in Belgium, so I will continue in Dutch)

Uw carrière in hoogste versnelling? Met Dolmen start u alvast in pole-position! Kom op 1 december naar het Dolmen jobevent met aansluitend karting. Ontdek de voordelen van werken bij Dolmen, een dynamisch ICT-bedrijf, waar een "no nonsense" bedrijfscultuur centraal staat.

Dolmen is nu reeds één van de belangrijkste spelers op de Belgische ICT-markt en heeft de duidelijke ambitie uit te groeien tot de absolute nummer 1 in Java- en Microsoft-competenties, dit op zowel applicatief als infrastructureel vlak.
Maar daarvoor hebben we dringend nieuwe krachten nodig, mensen die de gedrevenheid en ambitie hebben om op hun terrein de beste kwaliteit na te streven. Dolmen voorziet de perfecte omkadering om uw talenten tot volle bloei te laten komen en uw carrière te sturen in de richting die u wilt.
Als ervaren informaticus hoort u bij ons thuis. Naast een uitdagende en afwisselende functie, kan u ook genieten van de uitgebreide knowhow van Dolmen, doorgroeimogelijkheden, .

Schrijf je in op
De mensen die mijn naam opgeven in het Commentaar-veld (of mij verwittigen dat ze komen), mogen bij aanwerving rekenen op deelname in mijn aanbreng-premie ;-)

Bij eventuele vragen mail je me gerust. Voor een overzicht van alle beschikbare functies kan je terecht op

Tot binnenkort?

Stefanie Worm is het liefste vrouwtje van de wereld.
Melina is de liefste schatsie van de wereld (Erik De Maeyer).