Archive for the ‘Code’ category

jQuery Hover for Multiple Buttons/Images

August 13, 2009

It’s been awhile since I have posted something with code up here. I figured a small post on a simple jQuery exercise that might help someone out.

The goal of this exercise is simple:
We want to have a hover effect to make ‘grey’ images become ‘colored’ when the mouse hovers over them.

The tools we will need:
jQuery library (http://jquery.com/), a webpage and some -grey and -clr (color) images.
Here are a few we will use in this exercise.

Here are some fun additional challenges I am going to toss in:
We will be doing this on a SharePoint welcome page which has the content (images etc) in a rich text field control. That means you can’t add any JavaScript where the images are being shown.

Solution Steps:
Here’s where I will go through how you can do this (pretty darned easily) and some simple recommendations.

  1. First you need to have a welcome page in SharePoint (or a generic html page). Then you are going to add image references. Each image should be named CONSISTENTLY. That way our code can be really simple and generic (which all developers love). As an example the ‘greyed out’ images will be named “Whatever -grey.gif” where the “-grey” is consistent. I added the hyphen in the off chance that when we replace the -grey later on, there might be a -grey somewhere else in the URL (unlikely, but should make it unique; if you really want to go the extra mile you could even use a GUID).As for the ‘coloured’ images we will name these “Whatever -clr.gif” where again -clr is consistent.What we get then is basically a bunch of <img> tags pointing to -grey to start us off. In this case we will add the following code to our normal rich text field control on the welcome page.
    <DIV>TIPS AND TRICKS</DIV>
    <DIV>
    <IMG class=“ColourChange” alt=“Word 2007” src=https://webaddress/IconImages/MS-Word-grey.gif&#8221;>
    <IMG class=“ColourChange” alt=“Outlook 2007” src=https://webaddress/IconImages/MS-Outlk-grey.gif&#8221;>
    <IMG class=“ColourChange” alt=“Excel 2007” src=https://webaddress/IconImages/MS-Excel-grey.gif&#8221;>
    <IMG class=“ColourChange” alt=“OneNote 2007” src=https://webaddress/IconImages/MS-Note-grey.gif&#8221;>
    </DIV>
  2. You need to add the jQuery library reference to the page. You can do this via inserting it into the masterpage, page layout, or into something like a content editor webpart. For this example I will just toss it, as well as the script I will be using into a Content Editor WebPart (CEWP).
    <script type=‘text/javascript’ src=https://webaddress/_layouts/ThirdParty/JavaScript/jquery.js&#8217;></script>
    (Can be anywhere, just giving example).
  3. Add this code to either a CEWP, Master Page, or Page Layout (as defined earlier). So that when the objects with a class assignment of ColourChange are hovered over they change their source image.
    <script>
    $(document).ready(function(){
    $(“.ColourChange”).hover(function()
    {

    $(this).attr(“src”,$(this).attr(“src”).replace(‘-grey’,‘-clr’));
    }, function()
    {

    $(this).attr(“src”,$(this).attr(“src”).replace(‘-clr’,‘-grey’));
    });
    });

    </script>
  4. All done. Even if new images are added as long as we assign the appropriate class and ensure the script is running our hover effects should all be consistent.

This was a pretty specific example but the important things to note here were that we wanted consistent naming conventions so that we could write a fairly generic script to change the src attribute of any object with the ColourChange class. In our example we used a replace to accomplish this. You could have just as easily changed the position, size, or other things as well.

We also have HTML code that is flat and simple without any need for onmouseover events, or (IMO) bad things like that. So the code was clean and simple (as well as accepted by picky controls like the Rich Text Field control in SharePoint) and the script was pretty simple and clean.

Hope this helps someone,
Richard Harbridge

Development Specializations, Enhancements, and Experience

March 30, 2009

I found this interesting and can see many different benefits and advantages to using visual organization techniques and spatial representation for development activities.

Code Canvas: http://news.softpedia.com/news/Code-Canvas-Spatial-Representations-of-Code-107958.shtml

This is a very important concept and I really hope it goes much further than this in the coming years.

We need more creative ideas like this to take place. The concept of being able to see visually represented relationships in code is so key when dealing with how large our development platforms, languages, and services have become.

The entire development experience is still rapidly changing. At the heart of it is our growth and change as a society. Businesses are becoming smaller and more specialized. This allows the business to be extremely focused and deliver more than a larger more broad based competitor (in that particular specialization). More and more we see trends of people becoming experts and specialists in specific niches, and this also maps out to how development is evolving.

For each small style or section of development we create specializations. We have so many different development languages; all with their own patterns and skill sets. Yet at the same time the reason many people choose a development language is a direct result of the tool set, services, community, and overall development experience of that language.

Consider all the different technologies we interact with regularly. Now imagine how many ways those technologies can be broken down. How complex each of those technologies actually is and how hard it is to wrap your head around the layers and relationships each element of that technology might possess.

If we take SharePoint as an example we have front end developers who might be further specialized as experts in master page design, developing themes, page layouts etc. This can be broken down further. Think of what a master page, or page layout could contain. They could be specialists in JavaScript, XSL, HTML, or CSS. We could break that down further and say JavaScript specialists could be further specialized in AJAX or JQuery etc. (Yes I see resume’s all the time with “AJAX expert”, or “JQuery dev experience”)

Think about how complicated the development experience, processes and specializations can be on the front end. There is a lot more there than many people realize. And even as developers we sometimes forget how many skill sets we actually learned in order to develop that SharePoint brand so effectively.

Then the back end get’s even more specialized. Think of all the different pieces of the SharePoint pie. We have workflow specialists who understand the many nuances of workflow development.  We have search specialists who need to understand how language is interpreted and how the most relevant content can be found. Think of how web content or web publishing experts like Andrew Connell understand the many nuances of web publishing. Then there’s the entire BI layer which might go beyond KPI’s, Excel Services, and the such right into SQL Reporting Services, or Performance Point Services. Or how about the BDC or integration specializations?

Now think about that for another second, and you realize that there is normally an IT Administration or IT Pro side to each of these for configuration, implementation and management, as well as a development side.

Now think of one of those pie pieces I mentioned like workflow development and think of how we normally have people who build forms, and business logic, another group who might do data access layer work, another group who might build utilities for both groups etc etc. It’s extremely complicated and the deeper you get the more and more you realize how much is really there under the surface.

Now imagine how all of this impacts communication, how it impacts learning, or staying up to date or fully understanding a product or particular technology.

As a direct result of all of this specialization the entire field of development and technology is rapidly evolving in how we train, learn, and interact. More certifications come out every day, new programs and courses from education groups. More training companies pop up. At the same time we have a wealth of new development tools. Teams and companies that just build better tools to make the development, or learning experience easier.

Tools to build the communities around these groups or help them communicate are generated and tested every day. Or tools to help us achieve a better understanding of the different things we develop, build, or utilize.

We need to continue to grow, innovate and build our development support framework otherwise it will become exceedingly difficult to keep up with the complexities of our technology, and the demands of our users.

This project from Microsoft Research is a great step to helping us better understand just how large and complex our code, services, and development experience has become.

Hope this helps,
Richard Harbridge

SharePoint Developer Challenge

March 2, 2009

Paul Andrew released a very exciting announcement last Friday (http://blogs.msdn.com/pandrew/archive/2009/02/27/microsoft-sharepoint-developer-forum-challenge-march-april-and-may-2009.aspx). The announcement was that Microsoft is running a contest for people who contribute to the SharePoint developer forums! (http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/threads/)

There are some pretty sweet prizes up for grabs:

  1. 1st Prize – a 120GB Zune
  2. 2nd Prize – an Xbox 360 Arcade
  3. 3rd, 4th, 5th Prize – a 7” SharePoint Branded Digital Photo Frame

I am also going to quote how to enter from Paul’s post here:

How do I enter?
If you wish to participate in this Contest, you must FIRST register before the close of the Monthly Prize Period you are entering by sending an e-mail to answer@microsoft.com that conforms to the following requirements:

The subject line of your e-mail must read – ‘Forum Promotion’
1. The body of your  e-mail must contain the following information:
2. First and last name.
3. Email address
4. Forum sign-in name, which we’ll use to identify your answers.

This is great news for those who like contributing and helping people in the community as they now have a chance to get something back, but it is also terrific because hopefully it drives far more people to contribute on the forums. I also hope it becomes a regular thing. *wink wink to the Microsoft teams*

There has been a lot of debate especially around SharePoint Development support and resources from Microsoft as we have progressed through SharePoint 2007’s maturity. Some individuals feel Microsoft may not have released enough information (especially in the beginning) and support for developers learning and building powerful SharePoint based solutions.

In my mind the community will always be far more effective at creating documentation and parsing out a large number of recommendations and best practices than Microsoft can be on an almost open ended platform like SharePoint.

While I am in agreement that it can be frustrating (trust me I know) for new or existing developers to find certain information on classes, methods, or development related material for SharePoint (especially at the beginning of the SharePoint 2007 release), it is extremely satisfying to see Microsoft do initiative after initiative to help support the Microsoft Development community.

Here is another simple example of Microsoft trying to help the community grow and become stronger and I just wanted to say thank you to both the community and Microsoft for working together so well and striving to become better all the time.
Richard Harbridge

Show Content to Anonymous Users/Hide Content from Logged in Users

February 12, 2009

A while ago I made a quick post about the SPSecurityTrimmedControl and how it can easily be used to hide any content based on permissions. (https://sharepointkb.wordpress.com/2008/09/02/hide-content-or-controls-based-on-permissions/)

Jason Coleman brought up a good question which was “How can you hide content from someone who is logged in?” (As opposed to anonymous access.) This could be used to hide registration links, sign in links, and other custom content you might have.

The answer is very simple. We just add javascript that hides controls or that changes the look of elements on the page into the SPSecurityTrimmedControl. This javascript would only render when users have the required level of permissions so anonymous users would see the content, but it would be hidden for logged in users. 🙂

Simple Example:

<div id=“RegistrationLink”>REGISTER</div>

<SharePoint:SPSecurityTrimmedControl ID=SPSecurityTrimmedControl1  PermissionsString=CreateAlerts runat=server>
<script type=”text/javascript” language=”javascript”>
document.getElementById(RegistrationLink).style.display = “none”;
</script>
</SharePoint:SPSecurityTrimmedControl>

IMPORTANT NOTE: Of course you called also use the ASP login view control to do this as well, and this is probably recommended since it’s designed to do just that. LoginView Control: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.loginview.aspx

I am merely trying to illustrate other uses for the above control because I like it so much. 🙂

Hope this helps someone,
Richard Harbridge

Tips for SharePoint Developers

February 9, 2009

If you are a SharePoint Developer and you haven’t read this technical article: http://msdn.microsoft.com/en-us/library/bb687949.aspx read it now. I can pretty much guaranatee there is something helpful and useful for any SharePoint developer contained within the Best Practices: Common Coding Issues when using the SharePoint Object Model.

It was also updated in January, so even if you have read it before, take another look over the updates. 🙂
Richard Harbridge

Application Lifecycle Management Resource Center

February 2, 2009

Microsoft has released a new resource center for Application Development on SharePoint Server. This is good news because it aggregates a large amount of developer information in once place, and for those of you who are new to SharePoint development I highly recommend visiting the resource center and taking a look around.

http://msdn.microsoft.com/en-us/office/cc990283.aspx

Thanks to the Microsoft team and Paul Andrew for letting us know about the new resource center (http://blogs.msdn.com/pandrew/archive/2009/02/01/sharepoint-development-and-application-lifecycle-management.aspx)
Richard Harbridge

SharePoint Developers: SPDisposeCheck Release

January 30, 2009

This is probably redundant as pretty much everyone has blogged about it but just in case you don’t already know: SPDisposeCheck was released (hot and necessary for all dev’s as far as I am concerned).

But don’t take my word for it just check the blogging communities absolute joy on the totally sweet release:

  1. SharePoint Blog: http://blogs.msdn.com/sharepoint/archive/2009/01/29/spdisposecheck-released.aspx
  2. Paul Andrew: http://blogs.msdn.com/pandrew/archive/2009/01/29/spdisposecheck-v1-3-1-is-released.aspx
  3. Jan Tielens: http://weblogs.asp.net/jan/archive/2009/01/30/essential-sharepoint-developer-tool-spdisposecheck.aspx
  4. Andrew Connell: http://www.andrewconnell.com/blog/archive/2009/01/29/SPDisposeCheck–This-should-be-in-EVERY-SharePoint-developers-toolbox.aspx
  5. Gary Lapointe: http://stsadm.blogspot.com/2009/01/spdisposecheck-released.html

Hope you all give it a try and it helps save you time or enhance your development,
Richard Harbridge

P.S – When a friend calls you up around 11pm and says: “do you want to go tobogganing at midnight with a bunch of friends”, and you work at 6am the next day it is a wonderful idea to agree to go and have the time of your life. Also making pizza’s at a closed pizzeria at 3am in the morning is a great way to warm yourself up and apparently enjoy the unique experience of a pizza dough fight.

Add Some “Sex Appeal” with Silverlight and JQuery

January 23, 2009

Most of you are hopefully aware of Jan’s “SmartTools” for SharePoint on codeplex: http://www.codeplex.com/smarttools/. However just in case you aren’t I highly recommend taking a look at them. Recently Jan uploaded new versions of these tools (http://weblogs.asp.net/jan/archive/2009/01/22/new-release-of-the-smarttools-for-sharepoint-project.aspx), and I have personally used some to spread ideas or awareness of what silverlight/jquery can do in SharePoint (along with a few tweaks of my own).

One thing that’s really nice about the silverlight chart controls (as an example) is how they can generate ‘sex appeal’ for that presentation or proposal you are working on. It’s one thing to see functionality, and potential, but when you see cool charts, graphs, and interactive elements it normally generates alot of good excitement, and since Jan’s done most of the work to give you some examples (thanks Jan ;)) you just need to install, do a bit of configuration and voila, you have some cool content features that you can actually use right away.

There are plenty of other great silverlight and jquery projects and extensions for SharePoint out there as well.

Some Other Silverlight posts or projects I recommend taking a gander at:

  1. http://www.codeplex.com/SL4SP (Silverlight Blueprint for SharePoint)
  2. http://msdn.microsoft.com/en-us/magazine/dd148643.aspx (Great article on using Silverlight WebPart’s and an exaple media player one.)
  3. http://www.triplewood.com/triplewood/html/SharePoint2007.aspx (SharePoint Silverlight Browser)

Some Other jQuery posts or projects I recommend taking a gander at:

  1. http://www.endusersharepoint.com/?p=1110 (Good intro and real solution for a SharePoint Issue using jQuery)
  2. http://httpcode.com/blogs/PermaLink,guid,c26d2d3f-f389-44d7-bd8f-2fae5c8a1415.aspx (Example of how to use it for a ‘select all’ functionality.
  3. http://www.codeplex.com/ShUIE (Inject JS and CSS fragments based on context of page.)

If you haven’t played with Silverlight or jQuery yet then hopefully this will help motivate you, or help you understand some ways it can be used (with minimal effort),
Richard Harbridge

How to Customize SharePoint Alerts

January 20, 2009

So I have been looking for a workaround for something related to alerts and stumbled across this wonderful article on how to create customized alert notifications, and/or customized alert emails for SharePoint.

http://blogs.msdn.com/sharepointdeveloperdocs/archive/2007/12/07/customizing-alert-notifications-and-alert-templates-in-windows-sharepoint-services-3-0.aspx

If you have ever wanted to customize the alerts SharePoint sends out then this bad boy is probably the place to look (since I haven’t seen anything better).

To give a high level summary of what the article explains:

  1. How to customize the timer interval for alerts (immediate alerts are sent out after a delay determined by the timer interval).
  2. How to customize the alert templates (Each list type pretty much has one).
  3. How to customize the alert email.
  4. How to create your own alert template (instead of customizing one).

Hope this helps someone working with Alerts,
Richard Harbridge

SharePoint Mobile Development Help

December 2, 2008

So today I came across a terrific question.

“I’ve reviewed MSDN’s documentation:
http://msdn.microsoft.com/en-us/library/ms464268.aspx

However it still leaves me at a bit of a loss on the best strategy for rendering custom web parts for mobile browsers.

Has anyone had any experience in creating custom web parts that will detect a mobile browser and render accordingly?

Here are my questions:

1. What is the best way to detect that the web part is being viewed by a mobile browser. Is this a good approach?

2. Is it better to create a “mobile skin”, and have that skin as a configurable option, then configure the web part accordingly on the mobile page layout? I was thinking this might be better as it would leverage SharePoint’s browser detection as found in compat.browser .”

This is a good question.

Mobile pages are pages that are designed for Mobile browsing. If you open that page in your browser, it will render exactly the same as it would in the phone. This is necessary to improve usability and compatibility with all of the phone operating systems/browsers out there. (Plus it makes testing easier, don’t forget to have an emulator in your testing environment though as there are subtle differences in how phone browsers may render content.)

The secret to a good mobile page/part/anything is understanding Microsoft’s recommendations and use of their normal mobile pages. When you go to the http://portal/_layouts/mobile page you are visiting the mobile pages of SharePoint. This allows you to modify lists, and libraries, but has limitations related to how mobile devices render certain objects and the fact you don’t want to overload a mobile device with useless data.

Take a look at the mobile pages of SharePoint. These are found within the 12 hive, and you can examine how they build/render mobile content. “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\MOBILE” Notice they do not use webparts. A webpart in itself really just renders HTML and processes server side code. Instead they use controls which you can also use.

If you think about it the pages you develop that house controls should be stored with the other Mobile pages of SharePoint. SharePoint does all the mobile checking for you, and your developed material sits/works in the same place. So instead of trying to check if the user is using a mobile device, you can assume if they are viewing the mobile pages that they are, and if they are using the non mobile pages they are not.

My advice would be to read all of the articles/sections here: http://msdn.microsoft.com/en-us/library/ms464268.aspx (especially the fields part) and take a good look at those files in the Hive Directory, and then finally look over the Microsoft.SharePoint.MobileControls namespace: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.mobilecontrols.aspx these controls can really help, and if you can use them, do so, don’t reinvent or re-create everything if you don’t need to.

By looking these over you should be able to figure out how to best develop for mobile using SharePoint (the key to using SharePoint is building/using what they have already done, don’t do it all on your own, it will take much longer and be more prone to customization issues.)

Hope this helps,
Richard Harbridge

P.S – Wondering what mobile devices are supported and have been tested? Find that out here: http://support.microsoft.com/kb/930147