stackemedia

‘Value does not fall within the expected range’ error when viewing page settings and schedule

This was posted in MOSS/Infopath on April 29th, 2010

This is caused by a hostname change.

When a page is created it holds an absolute reference to its page layout:

<mso:PublishingPageLayout msdt:dt="string">http://dummylink.stackemedia.co.uk/_catalogs/masterpage/aPage_Layout.aspx, A Page Layout</mso:PublishingPageLayout>

This needs to be updated to reflect the hostname change. To do this:


  • Open the site in SharePoint Designer
  • Check out the page
  • Export the page – File > Export
  • Open the content of the page and change the hostname as appropriate
  • Return to SharePoint Designer and import the page – File > Import – overwriting the existing page
  • Check-in the page and approve

JQuery Set / Get form fields

This was posted in jQuery on August 28th, 2009

Ever wondered how you could use jQuery to get and set form fields?

First of all you will need to get the latest version of the jQuery framework from http://jquery.com/.

Next you will need to reference it in your web page – between the “head” tags (1.3.2 was the latest version of writing this).

< script src='jquery-1.3.2.min.js' type='text/javascript'>< /script >

To set the value of a combo box on you form, add the following script (after the reference to the jquery framework), where 1 is the second item in the combo box.

$('[name=yourlistboxname]')[0].selectedIndex = 1;

To set the value of an text box, use the following code:

$('[name=yourtextboxname]').val('texttoadd');

To set a checkbox to checked, then use the following code:

$('[name=yourcheckboxname]')[0].checked = true;

That’s all there is to it.

To get the form value you could do something like this:

var myvalue;
myvalue = $(‘[name=yourtextboxname]‘).val();
alert(myvalue);

View the Demo here, or download the code.

Web enabled feedback form

This was posted in Development, MOSS/Infopath on June 19th, 2009

You may want to include a feedback form or questionnaire on your Share Point site. Not every one will have the InfoPath client installed on their local machine, so the best way to ensure that everyone can access the form is to web enable it.

Enabling the form for use within a web browser is fairly simple: the only drawback being that you will be fairly limited during design as to what controls and functionality you might use. Saying that, for a simple survey, you won’t need anything beyond the basics.

To start off it would be best to setup your site and document libraries first. (I will presume that you do not have a site setup already so we will start from there). Once the site and libraries have been setup, we will create the form in InfoPath.

Read the rest of this entry »

Get first day of current month (VB)

This was posted in Visual Basic on June 17th, 2009

The following code will return the first day in the month as a string.

=DATESERIAL( YEAR(TODAY()), MONTH(TODAY()),1 )

Get whether a given date is on a weekend or not (VB)

This was posted in Visual Basic on June 17th, 2009

Function returns false if the passed date is a weekend and true if the date is on a working day.

Function GetWeekDay(ByVal raisedDate As Date) As Boolean
Dim passedDayNumber As Integer
passedDayNumber = DatePart(“w”, raisedDate)
If passedDayNumber = 7 Or passedDayNumber = 1 Then
return false
Else
return true
End If
End Function

Re-seeding a table id (SQL)

This was posted in SQL on June 17th, 2009

Use the code below if you want to restart the id column of a table from 0.
This is most useful if you have cleared a table and want to have the automatic generation of the id field to start at zero again.

DBCC CHECKIDENT(‘yourTable’, RESEED, 0) ;

Check if a column exists and delete it (SQL)

This was posted in SQL on June 17th, 2009

Exactly what the title says, checks if a column exists and then deletes it.

IF exists(SELECT id FROM syscolumns WHERE name LIKE ‘yourColumn’)
ALTER TABLE yourTable DROP COLUMN yourColumn

Get the day of the week (SQL)

This was posted in SQL on June 17th, 2009

Use to find the day of the week and return an integer.

SELECT TOP(5) DatePart(WEEKDAY, [EnquiryRaisedDate]) AS ‘DayOfWeek’, [EnquiryRaisedDate] FROM [vEnquiry]

To find the named day of the week, use:

SELECT TOP(5) DateName(WEEKDAY, [EnquiryRaisedDate]) AS ‘DayOfWeek’, [EnquiryRaisedDate] FROM [vEnquiry]

Create a JavaScript tooltip

This was posted in JavaScript on June 17th, 2009

Use the following code to create a JavaScript tooltip. Click here to view an example.

First add html to your page to create the popup:

<div id=”FloatBox” class=”hideFloatBox”>Hello World!</div>

Then add the following CSS to your style sheet (between the < head> tags (or you could use a CSS style sheet):

<style type=”text/css”>
.hideFloatBox
{
display: none;
}

.displayFloatBox
{
position: fixed;
_position: absolute;
z-index:200;
}

#FloatBox
{
padding: 5px;
width: 200px;
height: 20px;
border: solid 1px #cecece;
background-color: #ffffff;
}
</style>

Now add your JavaScript to the page (also between the <head> tags:

<script language=”javascript” type=”text/javascript”>
var floatBox;
var boxVisible = false;
var nav = (navigator.appName == “Netscape”);
var Xoffset = -5;
var mouseX;
var mouseY;

if(nav)document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMouse;

///< summary>
/// Gets the mouse position on screen.
///< /summary>
function getMouse(e)
{

mouseX = (nav) ?e.pageX : event.x;
mouseY = (nav) ?e.pageY : event.y;

if(boxVisible)
{
moveFloatBox(mouseX, mouseY);
}
}

///<summary>
/// Moves the floating box.
///</summary>
function moveFloatBox(x, y)
{
floatBox.style.left = (x + Xoffset) + “px”;
floatBox.style.top = (document.body.scrollTop + y + 20) + “px”;
}

///< summary>
/// Displays the floating box.
///< /summary>
function showFloatBox()
{
floatBox = document.getElementById(“FloatBox”);
floatBox.className = “displayFloatBox”;
boxVisible = true ;
}

///< summary>
/// Hides the floating box.
///< /summary>
function hideFloatBox()
{
floatBox.className = “hideFloatBox”;
}

</script>

Checking for valid Email (C#)

This was posted in C#.NET on June 17th, 2009

Check for valid email using REGEX expression.

// check to see if it is a valid email
if( txtEmailAddress.Text != “Enter Email” && !Regex.IsMatch(txtEmailAddress.Text, @”^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$”) )
{
lvalEmail.Visible = true;
lidPage = false;
}
else
{
lvalEmail.Visible = false;
}

Tested browsers: firefox, chrome, IE8