moopoo.net
Fishing, technology and anything else

Removing element from web.config on feature de-activation

March 15th, 2010 by Matt
public override void FeatureDeactivating(SPFeatureReceiverProperties properties) {
 
            SPSite site = (SPSite)properties.Feature.Parent;
 
            SPWebConfigModification controlsSection = new SPWebConfigModification("controls", "configuration/system.web/pages");
            controlsSection.Owner = "My.Menu";
            controlsSection.Sequence = 20;
            controlsSection.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureSection;
            controlsSection.Value = "<controls></controls>";
 
            SPWebConfigModification addElement = new SPWebConfigModification(
                @"add[@tagPrefix=""SharePoint""][@namespace=""My.Menu""][@assembly=""My.Menu, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cd3368f0ff736bff""]", 
                "configuration/system.web/pages/controls");
            addElement.Owner = "My.Menu";
            addElement.Sequence = 40;
            addElement.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
            addElement.Value = @"<add tagPrefix=""SharePoint"" namespace=""My.Menu"" assembly=""My.Menu, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cd3368f0ff736bff"" />";
 
            site.WebApplication.WebConfigModifications.Remove(controlsSection);
            site.WebApplication.WebConfigModifications.Remove(addElement);
            site.WebApplication.Update();
            site.WebApplication.WebService.ApplyWebConfigModifications();
 
    }

Posted in SharePoint | No Comments »

Adding element to web.config on feature activation

March 15th, 2010 by Matt
public override void FeatureActivated(SPFeatureReceiverProperties properties) {
 
            SPSite site = (SPSite)properties.Feature.Parent;
 
            SPWebConfigModification controlsSection = new SPWebConfigModification("controls", "configuration/system.web/pages");
            controlsSection.Owner = "My.Menu";
            controlsSection.Sequence = 20;
            controlsSection.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureSection;
            controlsSection.Value = "<controls></controls>";
 
            SPWebConfigModification addElement = new SPWebConfigModification(
                @"add[@tagPrefix=""SharePoint""][@namespace=""My.Menu""][@assembly=""My.Menu, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cd3368f0ff736bff""]", 
                "configuration/system.web/pages/controls");
            addElement.Owner = "My.Menu";
            addElement.Sequence = 40;
            addElement.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
            addElement.Value = @"<add tagPrefix=""SharePoint"" namespace=""My.Menu"" assembly=""My.Menu, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cd3368f0ff736bff"" />";
 
            site.WebApplication.WebConfigModifications.Add(controlsSection);
            site.WebApplication.WebConfigModifications.Add(addElement);
            site.WebApplication.Update();
            site.WebApplication.WebService.ApplyWebConfigModifications();
 
    }

Posted in SharePoint | No Comments »

Securing custom application pages in _layouts directory

February 26th, 2010 by Matt

I had a need to be able to only allow site collection admins to see some custom pages I had deployed into the _layouts directory.
Create a custom code behind class for your aspx that inherits from LayoutsPageBase.
Next, override the OnLoad method in your code behind and add the following code

if (!SPContext.Current.Web.UserIsSiteAdmin)
              SPUtility.HandleAccessDenied(new Exception("You need to be a site administrator to access this page."));

This will redirect the user to the built in SharePoint Access denied page, for consistency.

Posted in SharePoint | No Comments »

Validation Group with SharePoint DateTimeControl

February 16th, 2010 by Matt

The SharePoint DateTimeControl has a property called IsRequiredField, which will act like a RequiredFieldValidator for the control. The problem is when working with web parts in SharePoint calling Page.Validate in your web part can have unexpected results. It often ends up firing validators elsewhere on the page, particularly if the web part is used on a list form for example.
One answer of course is to use a validation group in your web part, this is where the DateTimeControl falls down as it doesn’t have this property.

The answer to this to create a validator in your webpart and hook it into the TextBox element of the DateTimeControl, which will then allow you to set the validation group on it.

To do this use the following code when you create your validator.

valReviewDate.ControlToValidate = string.Format("{0}${0}Date", dteReview.ID);

This post, describes how to do it from code in front.

Posted in SharePoint | No Comments »

Disable Web Part button after clicking

February 16th, 2010 by Matt

Not sure how, I got to the end point of this so there may be other ways of doing it.
Basically I had a web part the when the button was clicked I needed to disable it.
Adding .Attributes["onclick"] didn’t seem to work, and after trying a few things I managed to get it working this way.
Add the following code into OnPreRender of the web part, assuming cmdGenerate is the name of your button.

cmdGenerate.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(cmdGenerate, "") + ";this.value='Please wait...';this.disabled = true;");

Posted in SharePoint | No Comments »

Using Custom Masterpage in _layouts directory

August 24th, 2009 by Matt

To use a custom or the default masterpage in custom aspx pages located in your _layouts directory use the following code in the code behind for the page.
N.B I didn’t declare any masterpage useage in the actual aspx file.

protected override void OnPreInit(EventArgs e)
{
    base.OnPreInit(e);
    // Set the masterpage to the default.master.
    using (SPWeb webCurrent = SPControl.GetContextSite(Context).OpenWeb())
    {
        string strUrl = webCurrent.ServerRelativeUrl + "/_catalogs/masterpage/default.master";
        // custom.master is your same default or main master page 
        // being used for main portal pages. Change that path according to your need
        this.MasterPageFile = strUrl;
    } 
}

Posted in Mobile, SharePoint | 1 Comment »

Apple Airport Extreme Disk Access and Windows 7

August 18th, 2009 by Matt

I was having issues accessing the drive I had hooked up to my Airport Extreme from Windows 7. Every time I would try to connect I would get the following error:

“unknown user, incorrect password, or login is disabled. Please retype the login information or contact the disk’s administrator (67)”

I eventually came across this thread on the Apple Support forums which offered the solution below.

Goto Start Menu
Search for: security
Click on Local Security Policy
Goto Local Policies> Security Options
Double Click on Network security: LAN Manager Authentication
Change level to: Send LM & LTLM Responses

Then, scroll down to Network security: Minimum session security for NTLM SSP
De-select Require 128-bit encryption
Hit OK

This worked for me, now I get full access to my HFS formatted disk from windows 7 and all other computers on the network.

Posted in Mac | 3 Comments »

Dell SX2210 Monitor

August 18th, 2009 by Matt

I had been toying with idea of getting a new monitor for a while. My requirements were pretty straight forward I think, I wanted something at least full HD on as small a monitor as I could get away with. I was originally looking at a 24″ but I wasn’t sure I had the desk space for it, I already have a 21″ widescreen Acer on there.

Then a few nights ago I came across the Dell SX2210 on the Dell website. It seemed to tick all the boxes, full HD (1920×1080), was a 22″ screen (well 21.5″ but who’s counting) and it looked the part. Best part was it had nearly £45 off so was only £175. There were some decent reviews of it on the dell review site so I decided to take the plunge.

Delivery was quick, ordered very late Thursday Night and it arrived Monday morning.

First impressions

The monitor looks very stylish, and has a white back with small white trim noticeable at the front bottom.
I can’t see any dead pixels on there which is a bonus.
The screen is very clear and bright. The monitor is setup at the side of an Acer AL2016W and is noticeably brighter with better colours. The Acer seems dull and the whites don’t seem as crisp.

I’m hoping to hook the Xbox 360 up via HDMI to see how it looks playing games b ut for day to day use I’m more than impressed.

It does have a glossy screen, which I tend to prefer and I don’t really have any issues where it is sat in my office.

I would definitely recommend this monitor so far, I may even treat myself with another one to replace the Acer which is a poor monitor in all honesty.

Posted in Technology | 1 Comment »

Wordpress for iPhone

May 18th, 2009 by matt

Just having a play with Wordpress for iPhone to see how it is.
Seems pretty good so far although I noticed with 3.0 if I want to write the post in landscape mode, I can’t scroll to modify
other fields I have to put it back to portrait mode to get to them.

var test="my JavaScript test";

Posted in Fishing | No Comments »

Highlighting row on form error with jQuery

May 18th, 2009 by Matt

When showing errors in web forms, I thought it would be useful to highlight the row where the error occurred so the user can visually see where they they need to make changes. jQuery is the ideal way to do this for me as I didn’t want to do it server side.

To begin I set a CSS class on the error messages that were displayed in the td with the form element. An error message could be in the form of

<span class=".valError">You have selected an invalid date.</span>

Now all we have to do in jQuery is find all elements which match the class, remove any classes that may be on any of the td tags, then add a class to the tr in which the error exists.

$(".valError").each(function() {
    // remove all classes from any td's of the below the parent row
    $(this).parent().parent().find("td").removeClass();
    // set the class on the tr
    $(this).parent().parent().addClass('ms-informationbar');
})

That’s it.

You could optionally set the class of the td rather than or as well as the tr. The following line would help you achieve this.

$(this).parent().parent().find("td").removeClass().addClass('myErrorClass');

Posted in jQuery | No Comments »

« Previous Entries