Welcome to EMC Consulting Blogs Sign in | Join | Help

Michael Ciba's Blog

  • Enabling notifications for SqlCacheDependency using a database project

    Ok so if you are using a database project and you want to turn on notifications for the database once it is deployed so you can use handy things like "SqlCacheDependency" a good way I found was to add a “AfterDeploy” target to the “*.dbproj” file for the database project and then just call “aspnet_regsql”. This way you don’t have to remember to run the command each time you deploy the database from scratch and I think it’s cleaner than having explicit try/catch logic within your application to setup the notifications.

    <Target Name="AfterDeploy">
        <Exec Command="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe -d FakeDataBaseName -ed -S . -E" ContinueOnError="true" />
        <Exec Command="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe -d FakeDataBaseName -S . -E -et -t FakeDataBaseTable" ContinueOnError="true" />
    </Target> 

     

     

  • PowerShell Marches into SharePoint 2010

    So on my first look at the Managed References SDK for SharePoint 2010 contained in the technical preview (downloaded your copy from here) I noticed something very interesting the “Microsoft.SharePoint.PowerShell” namespace.

    On closer inspection of the classes defined in the SDK it would appear SharePoint 2010 is going to use PowerShell as part of it's deployment process to perform certain administrative tasks such as install a feature.

    Install-SPFeature FeatureId
    Enable-SPFeature FeatureId -Url http://server/site/subsite

    What's more it looks like you can write your own PowerShell cmdlets for use within a SharePoint deployment and all you have to do is get your cmdlet to inherit from “SPCmdlet”.

    So all I can say is get learning PowerShell as it looks like it's coming to SharePoint in a big way. Which isn't a bad thing at all :-)

  • Hiding the Site Actions Menu for certain users

    While working on a client site recently I was asked to hide the site actions menu and only allow certain users to view it. After a bit of digging around and searching I found the answer to be the “SPSecurityTrimmedControl”. Now the great thing about this control is that it only renders the contents of the controls it contains if the user has a matching permission level. Therefore the only thing I needed to do was create myself a custom permission level called “DisplaySiteActionsMenu” and assign that to the group or groups who should see the site actions menu. Once this was done all the standard users to the site didn't even know the site actions menu existed.

    Below is an example of how I updated the master page for the site to make this work.

    <SharePoint:SPSecurityTrimmedControl ID="stcHideMasterPageItems" PermissionsString="DisplaySiteActionsMenu">

    <PublishingSiteAction:SiteActionMenu runat="server"/>

    </SharePoint:SPSecurityTrimmedControl>

     
  • Debugging hidden features in SharePoint

    Well it’s been a while since I have done a blog entry so I thought I would ease myself back into them with a small post about how to debug a hidden feature.

    As everyone knows in SharePoint you have the ability to make a feature hidden which means it doesn’t show up via the UI. This is useful if you don’t want users deactivating or activating a feature in the wrong site etc and making a mess of things. However, to debug these features I until quite recently use to switch the “hidden” attribute back to “false” so I could activate the feature via the UI and attached the debugger to the “w3wp” to see what gremlins were making my code go up in a cloud of smoke. However I learnt the other day about the “Debugger.Launch();” method which enables you to launch a debugger for your code and attach to the relevant process to enabling debugging (see http://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.launch.aspx).


    Now all I need to do when I want to debug my hidden feature is add “System.Diagnostics.Debugger.Launch();” at the start of the feature activate or deactivate. Additionally this same technique can be used to debug custom stsadm commands.

  • ThickBox, IE6 and a little secure and nonsecure item problem

    So it’s been a fun packed morning looking at an issue within ie6 that was causing the “This page contains both secure and nonsecure items” prompt to be displayed then viewing a page over HTTPS.

    The problem itself only reared its ugly head when the page tried to open a UI dialog to the user using the “ThickBox” add-on to jquery. So after a bit of digging around I found out that IE6 shows this message because “ThickBox” is adding an iframe to the page without the src attribute set. In order to fix the issue then all you need to do is add a dummy src attribute to the iframe when it is appended to the page by “ThickBox”. See the example below.  The bit of code you need to update can be found on line 38 within the thickbox.js file.

    Original Code

     $("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");

    Updated Code

    $("body").append("<iframe id='TB_HideSelect' src='java script:false;'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");

     

     

  • Easy client side validation for check boxes

    The other day while doing adding some validation in an ASP.NET application for some check boxes  I discovered a method I hadn't used before within the “ClientScriptManager” called “RegisterExpandoAttribute”. So you may well be asking yourself what does this rather strange sounding method do? Well it enables you to add new attributes onto a html element via JavaScript. OK so now you are probably asking yourself why should I care? Well that is a good question. First off this method enables you to attach server side information to html elements and enable that information to be used at the client by JavaScript. Secondly by attaching the information this way the html you produce remains XHTML compatible as the additional information is added by JavaScript. This means when you view the source for the page no custom attributes are present.

    OK so what can you do with this? Well if you recall at the start of this entry I said I found this method while writing some code to validate check boxes. The way in which I used it was to attach additional attributes to a custom validator and then have the JavaScript function I defined for the client side validation use those additional bits of information to not only find the check boxes that were meant to be validated but highlight to the user which set of check boxes on the page failed to validate by adding to the containing element for the check boxes a CSS class that produced a nice red border. OK so the actual attributes I added were as follows:

    1.CssClassOfParentElement: This is used in the JavaScript function to find a specific html element by a CSS class.
    2.ErrorFieldCssClass: This is the name of the CSS class that should be applied in the event validation fails
    3.IdOfControlToAddErrorStyleTo: This is the ID of the html element that should have the “ErrorFieldCssClass” applied.

    Below is the JavaScript function I used to perform the validation on the client side.

    function validateCheckBoxes(sender, args)
    {
           var n = $("."+sender.CssClassOfParentElement+" > input:checked").length;
          
           var isValid = (n > 0);
           args.IsValid = isValid;
          
           if(!isValid)
           {
                $("#"+sender.IdOfControlToAddErrorStyleTo).addClass(sender.ErrorFieldCssClass);
           }
           else
           {
                $("#"+sender.IdOfControlToAddErrorStyleTo).removeClass(sender.ErrorFieldCssClass);
           }
          
    }


    The additional attributes were added as follows:

    //Called from page load
    private void RegisterClientSideValidationAttributesValidators()
    {
        // Add attributes for programming types check boxes to custom validator
        Page.ClientScript.RegisterExpandoAttribute(cvProgrammingTypes.ID, "CssClassOfParentElement", "validateCssExampleProgramming");
        Page.ClientScript.RegisterExpandoAttribute(cvProgrammingTypes.ID, "ErrorFieldCssClass", "errorField");
        Page.ClientScript.RegisterExpandoAttribute(cvProgrammingTypes.ID, "IdOfControlToAddErrorStyleTo", cblProgrammingLan.ClientID);

        // Add attributes for colours check boxes to custom validator
        Page.ClientScript.RegisterExpandoAttribute(cvColours.ID, "CssClassOfParentElement", "validateCssExampleColours");
        Page.ClientScript.RegisterExpandoAttribute(cvColours.ID, "ErrorFieldCssClass", "errorField");
        Page.ClientScript.RegisterExpandoAttribute(cvColours.ID, "IdOfControlToAddErrorStyleTo", pnlColors.ClientID);           
    }


    I have included with this post a small test application that demonstrates how I set up the validation.

    Enjoy!

  • Sharepoint feature activation and strange timeouts....

     

    So I have been meaning to write a blog entry for some time now and at last I have finally manage to drag together a few coherent sentences and get the ball rolling. So what topic have I picked to start my blogging experience with at Conchango? Well Sharepoint of course!

    Anyway down to business and the reason for the post is that the other day I had to deal with an issue surrounding a timeout when activating a feature via the "ManageFeatures.aspx" page within the Windows Sharepoint Services (WSS) user interface. The feature itself was somewhat of a beast and did a lot of work within the "FeatureActivated" method behind the screens setting up lists, creating content etc which meant it was going to take a long time to complete.  So a timeout issue?

    Well as it turns out yes. The problem is that activating a feature via the "ManageFeatures.aspx" page means that the request to activate the feature is handled by asp.net and as such is subject to the same rules that govern any asp.net request, including maximum execution time out.  For application pages that live within the layouts directory in the 12 hive such as "ManageFeatures.aspx" this timeout value can be changed by modifying the "web.config" at the root of the layouts directory. The actual value you need to change is the attribute called "executionTimeout" within the "httpRuntime" element. An example is shown below were the execution timeout has been changed to ten minutes.

    <httpRuntime executionTimeout="600" />

    Additional it is worth keeping in mind that this issue will not occur if have debug set to true within the compilation element of your sites "web.config" or you are installing and activating your features via "stsadm" at the command line and as such may not be identified until a site has been deployed into a environment that mirrors production.   

Powered by Community Server (Personal Edition), by Telligent Systems