Clinton's profileCherry BytesBlogListsGuestbookMore Tools Help

Cherry Bytes

Clinton Cherry does dot net
June 16

Generating SQL Scripts for Data

An issue I have always had is finding an easy way to generate SQL Scripts for moving data from one database to another. Obviously if you are doing a straight copy this is easy, however using only SQL Management Studio I was never able to find an easy way to get the data into a simply SQL script that I could give to a Database administrator for deployment.
 
Today I discovered a nifty commandline tool 'SqlPubWiz' that actually comes with SQL Server to do this.
 
Simply navigate on the server your database is on to the folder C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\ and within this folder (or in one of the versioned subfolders) you will find a tool called sqlpubwiz. By running this at the command line and pointing this to your database, you can easily now generate the SQL scripts you require for your data.
ie  sqlpubwiz script -d MyDataBaseName "C:\NameOfFileToGenerateScriptFo.sql" -dataonly
 
If you don't have the tool you can easily download it here: http://www.codeplex.com/sqlhost/Wiki/View.aspx?title=Database%20Publishing%20Wizard.
 
I found out about this on this great article at The Code Project - http://www.codeproject.com/KB/database/DatabasePublishingWizard.aspx.
June 05

Validating that a checkbox has been selected

Been doing heaps of stuff with jQuery lately, so thought I should start jotting down some of the more useable code that I have done.

A really useful bit of code was adding validation to check if at least one checkbox is checked. The following bit of code does that really easily.

 

First you will need to create a simple custom validator for your page:

 

<asp:CustomValidator ID="valCheckBoxes" runat="server"

                        ErrorMessage="You must select at least one checkbox"

                        ClientValidationFunction="CheckAnyCheckBoxChecked" Display="Dynamic"></asp:CustomValidator>

 

Once you have the validator, make sure that it has a ClientValidationFunction. You will then need to create this method. Using jQuery you can easily search for any checkbox that is checked. If none are checked, then throw the validation exception. Easy!!

 

<script type="text/javascript">

  function CheckAnyCheckBoxChecked(sender, args)

  {

    var isChecked = false;

    $("input[type=checkbox][checked]").each(

      function() {

         //Check if checkbox is checked

         if($(this).is(':checked'))

         {

            isChecked = true;

         }

      }

    );

   

    args.IsValid = isChecked;

    return;

  }

</script>

 

If you have specific checkboxes that you don't want to validate, then you can add a bit more jQuery to the script to check for specific items. Below I am doing a check on any checkbox that does not have the class 'NonMandatory' assigned to it (note:// I am using the parent check for the class as with ASP.NET the CSSClass of a checkbox is assigned to the span class that surrounds the checkbox control). 

 

<script type="text/javascript">

  function CheckAnyCheckBoxChecked(sender, args)

  {

    var isChecked = false;

    $("input[type=checkbox][checked]").each(

      function() {

        //Don't check for non mandatory check boxes

        if($(this).parent().hasClass('NonMandatory') == false)

        {

            //Check if checkbox is checked

            if($(this).is(':checked'))

            {

                isChecked = true;

            }

        }

      }

    );

   

    args.IsValid = isChecked;

    return;

  }

</script>

 

April 23

Invalid Security Validation in SharePoint code

Twice in the past week I have had the issue in my MOSS code where it is throwing an exception:

"The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again"

As it turns out the problem isn't so had to fix. Basically you need to set FormDigestSettings to disabled. This can be done in your code as follows:

SPWebApplication webApp = site.WebApplication;
bool formDigestSettingsEnabled = webApp.FormDigestSettings.Enabled;
webApp.FormDigestSettings.Enabled =
false;
//Do all your code in here where it is throwing the error..
webApp.FormDigestSettings.Enabled = formDigestSettingsEnabled;

This can also be fixed by turning off the security validation for an application in Central Admin (however I probably wouldn't recommend this):

Central Admin -> Application Management -> General Settings -> Turn security validation off

January 22

Launching an application from a link in SharePoint

When you are viewing lists of items in SharePoint, the context menu is fantastic as it allows you to edit documents directly from certain native applications. For example with a Word document you are able to select 'Edit In Microsoft Word' from the context menu, which when clicked fires up Microsoft Word and enables you to edit the document. However when you start creating your own custom webparts from SharePoint list items, you lose this ability. Today I had the challenge of providing a link to a document that was stored in a SharePoint list, but I needed to be able to fire the document up directly from the link.
 
After quite a bit of trawling through the web I found this great article which really got me going in the right direction:

http://wiki.threewill.com/display/is/2007/10/.

Basically you need to call a javascript method called dispex() which will open the application for you (instead of opening the document as read only).

So within my code I already had my Hyperlink control (lnkDocumentDownload) which was populated by an SPListItem. This also has the URL of the document set in lnkDocumentDownload.NavigateUrl. This needs to be set for this to work, and of course for applications that don't have integration with SharePoint, they will just use this link to go to the document.

What I needed to additionally add to enable the launching of the application was:

lnkDocumentDownload.Attributes.Add(

"onfocus", "OnLink(this)");
lnkDocumentDownload.Attributes.Add(
"onclick", @"DispEx(this,event,'TRUE','FALSE','FALSE','SharePoint.OpenDocuments.3','0','SharePoint.OpenDocuments','','','','2','0','0','0x7fffffffffffffff')");

Once I added this in, whenever I clicked the link in my control, it would behave in the same way as clicking on 'Edit in Microsoft Word'.

I also found some 'kind of' (not really) helpful documentation on the javascript methods on the Microsoft website here: http://msdn.microsoft.com/en-us/library/cc264013.aspx

January 21

Presentation on SharePoint Search and Longitude

Yesterday I did a presentation for the Perth SharePoint User group on MOSS 2007 search and enhancing it with Longitude (a product by BA Insight).
'Longitude' is a third party product by BA Insight which extends SharePoint's search capabilities to deliver document page previews, relevance optimization, parametric navigation, enhanced sorting and a number of other additional features. In this presentation Clinton will cover MOSS Search and how businesses are using it, then will give a demo of Longitude highlighting how this can be used to extend SharePoint Search to deliver a more efficient and relevant search experience for end users.
For details about the presentation check out the UserGroup site here.
If you are interested in downloading the presentation (which includes notes in the slides), then you can use one of the links below:
 
 
Thanks for visiting!
Please wait...
Sorry, the comment you entered is too long. Please shorten it.
You didn't enter anything. Please try again.
Sorry, we can't add your comment right now. Please try again later.
To add a comment, you need permission from your parent. Ask for permission
Your parent has turned off comments.
Sorry, we can't delete your comment right now. Please try again later.
You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
Complete the security check below to finish leaving your comment.
The characters you type in the security check must match the characters in the picture or audio.

Clinton Cherry

Occupation
Location
Interests
I basically love .NET stuff so thought that I would share different insights, thoughts and things that I discover during my day to day workings with .NET, C#, SQL and all those other related nerdy things that I do during my daytime hours.