Switching Dark/Light theme in Blend for Windows Phone

Today a small tip on how to change the design view of your windows phone 7 application in Expression Blend so you can see it in light or dark theme or check how all the different accent colors look:

This is basic functionality but when I asked around I noticed most people don’t know about this feature so that’s why I wrote this blogpost.

By default in Expression Blend your app will show using the dark theme and the blue accent color. To see how your app looks in white just open the Device window by clicking “Window” –> “Device”

blend device window

When the device window is opened you can switch to the light or dark theme by clicking one of the icons. You can also select the accent color from the pulldown box on the right.

blend select white theme

The result:

blackwhite blend

Happy Coding! Designing!

Geert van der Cruijsen

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

Microsoft Pubcenter not showing ads in your windows phone 7 app?

The free apps I had in the marketplace were running Google’s Admob as adprovider because when I wrote the apps Microsoft Pubcenter wasn’t available in the Netherlands yet. When I was upgrading my Apps to Mango I found out that version 4.0.4 that is currently the latest release of the Windows Phone Admob SDK is broken will always give you exceptions when you include this control. Seeing Google wasn’t to keen on fixing this since it was mentioned a lot in admob sdk Google groups I decided to switch to Microsoft Pubcenter because it came available for Dutch people.

Implementing the control is easy by just installing the SDK, create an account, adding the control to your page and filling in the applicationid and the adunitid. if you still need a guide this one explains all the details:

http://blogs.msdn.com/b/urmila/archive/2011/03/10/displaying-ads-on-windows-phone-7-apps-the-basics.aspx

So the control is added to the page and you’re ready to go. If you followed all the instructions the ads should show up fine. Not for you?

I had the same problem when I was testing my application. I did most of my testing in the emulator and the ads would show up fine right there. When I started testing on my phone I noticed that only the ad placeholder was shown for really short time and after that the ad was hidden. Trying to find out what the differences could be between my phone and the emulator my first thoughts were the Culture of the phone since my phone is running in Dutch Culture nl-NL and the emulator is running en-US by default. When I switched the culture on the emulator to being Dutch the ads also stop showing there.

So what is the problem and how did I fix it?

The Pubcenter Adcontrol has a nice event called “ErrorOccured” and you can subscribe to this event to see what is happening. (or just attach the debugger and set it to break on exceptions)

   1: public MainPage()

   2: {

   3:     InitializeComponent();

   4:     adcontrol.ErrorOccurred += new EventHandler<Microsoft.Advertising.AdErrorEventArgs>(adcontrol_ErrorOccurred);

   5: }

   6:  

   7: void adcontrol_ErrorOccurred(object sender, Microsoft.Advertising.AdErrorEventArgs e)

   8: {

   9: }

In the adcontrol_ErrorOccurred eventhandler you can log your error the adcontrol is throwing or handle it the way you want to. The error I kept getting when using the Dutch Culture was:

Microsoft.Advertising.Mobile.Shared.AdException – No ad available.

My guess was that this was happening because there aren’t any Dutch ads yet so I tried to change the settings of the adcontrol by changing the CountryOrRegion, Language and even the Latitude and Longitude attributes to somewhere in the United States but this doesn’t help. I made a ticket at the Pubcenter helpdesk and they told me a new algorithm just went live and it can be that there aren’t to many ads yet so it’s possible to get a disappearing ad control once in a while when you’re running less common cultures. Trying to change the country or culture DOES NOT WORK so you’ll just have to wait (It’s not like Admob is a better alternative since that one isn’t working at all)

I would encourage everyone to just leave the ad in and the requests to the Pubcenter servers will show that there is a lot of space for ads to be sold so advertisers will jump in and use this space.

Nokia seems the first to jump in because the last few days I seem to receive Nokia Lumia ads when using a Dutch culture :)

Oh btw this method also works when you’re having other issues with your ad control ofcourse. just check the exception to see what’s going on. The one thing I keep forgetting every time I add the AdControl are the capabilities in the WMAppManifest.xml. when you do this you’ll get another AdException:

Microsoft.Advertising.Mobile.Shared.AdException – Required capabilities are missing from manifest (WMAppManifest.xml): ID_CAP_NETWORKING, ID_CAP_PHONEDIALER, ID_CAP_IDENTITY_USER, ID_CAP_MEDIALIB, ID_CAP_WEBBROWSERCOMPONENT.

Geert van der Cruijsen

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

PinPin 1.2 update now available in the WP7 Marketplace

First note I want to make: The “Error retrieving ATM locations” bug is fixed in this release!

Here is the story on how it all went down:

Since PinPin’s launch last week I’ve been loaded with feedback from people, most of them were positive but there was also a large group of people who weren’t able to get ATM locations. At first I didn’t have any idea how this was possible since I had tested at many locations in the Netherlands and had asked several colleagues to test the app and it worked for everyone.

Luckily  lots of people were able to find the feedback form in my app and when I received a mail from Marco who had a dev unlocked phone and was receiving the errors I found my chance to find out what was causing the bug. I made a version 1.1 and submitted it to the marketplace (that wasn’t smart because that’s why it took so long to get 1.2 out) but also mailed it to Marco so he could test. 1.1 had the option to save the errors and send a mail with the Error messages and a stacktrace so I could see what was going wrong.

With the error report I received from Marco I could see it was something in the response from the webservice I’m calling to get the ATM data but still couldn’t see what the error was exactly. I again added more logging to the app and asked Marco to test again. This time I could compare my request and response from the server to his and then I found out: The Dutch regional settings were screwing things up. Ofcourse this is a major concern for an app that is only used in the Netherlands Smile

I fixed the bug but had to wait untill version 1.1 had passed certification before I could submit 1.2 Wednesday night 1.1 was approved and I immediately submitted 1.2. Today I received another mail from Microsoft that 1.2 also passed certification. From now on everyone should be able to use PinPin!

If you find any bug in version 1.2 please let me know and I’ll try to fix it asap again.

It can take a while before you’ll get the 1.2 update notification from your phone but you could also manually uninstall your current PinPin installation and reinstall from the marketplace you’ll download version 1.2.

Big thanks to Marco and everyone else who has send feedback concerning this bug. Hopefully you can enjoy PinPin now and if you do don’t try to rate and review the app, it only takes a few seconds!

 

1_thumb 2_thumb 4_thumb2

Oh and if you didn’t have PinPin yet, you can download it here:

Download PinPin for WP7

 

Geert van der Cruijsen

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

Introducing: PinPin for Windows Phone 7

I’m proud to announce my 2nd Windows Phone 7 application available in the marketplace. The new app is called PinPin and is an app to locate an ATM near your location. The app is really simple at this first release, just open the app and the app will retrieve ATM location information near your GPS location.

At this moment PinPin only works if you are located in the Netherlands because there is no worldwide ATM location data available. I’m still looking for this data so if someone knows where to get this please let me know.

PinPin Logo

Below are some screenshots of the application:

1 2 3
4 5 6
7 8

PinPin is available for FREE in the Windows Phone marketplace. download it by clicking the button below:

Download PinPin for WP7

Special Thanks to Christiaan Veeningen for telling me to build this app :)

If like or dislike the app please let me know by rating the app or by submitting a review. You can also contact me through twitter @geertvdc or leave a comment here on my blog.

This is currently the first release of PinPin. I have more plans for the app in the future, here is a roadmap of what to come:

  • Add Dutch language
  • Get Directions (Will have to wait for Mango)
  • Add more Bank logo’s
  • Add more countries
  • Review Comments I get from you!

Hopefully you’ll enjoy this new app!

Geert van der Cruijsen

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

WP7 App hub error: The [NeutralResourceLanguage] attribute is missing on the entry assembly. (2003)

Today the Microsoft Windows Phone 7 App Hub got a makeover. My new app was ready for deployment yesterday so logging into the new App hub to deploy my app today was the plan.

After uploading my .xap file the app hub told me the “NeatralResourceLanguage” attribute was missing with the following error:

The [NeutralResourceLanguage] attribute is missing on the entry assembly. (2003)

Not sure what this error means I started looking in Visual Studio. and found the solution for the problem.

  • In Visual Studio 2010 rightclick your project and choose properties
  • At the application tab click the “Assembly information…” button
  • Fill the Neutral Language in the popup
  • Press ok!
  • You’re ready to go!

image

It seems that the new App hub Checks up on more things than the old App hub did. The neutral language is probably something a lot of people will forget so hopefully this helps others who are receiving this error.

The Assembly information can also be changed manually the following way:

  • Open the properties directory in your WP7 project
  • Open the AssemblyInfo.cs file
  • Add the following line at the end of the file:
[assembly: NeutralResourcesLanguage("en-US")]

you’ll also need to add the following line at the top:

using System.Resources;

 

Happy developing and deploying!

Geert van der Cruijsen

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

My Windows Phone 7 Mango Beta review

The beta of Windows Phone 7.1 codename “Mango” was released last week and in this post I’ll write down my experiences with Mango that I had using it since the launch of the beta.

I’ll try to update this post when I bump into stuff I didn’t write about yet.This post isn’t about describing all new stuff since there are already dozens of other great blog posts about that but I’ll try to write my opinions about how these features are working out or what I am still really missing in Mango.

WP7-Mango

 

Lots of small features that make your life easier:

One of the things I enjoy the most about Mango are the small things that really annoyed me with the 7.0 release of Windows Phone 7, for example the shutdown button that automatically turned of your phone even when the phone is locked. Now in Mango you have to slide down after pressing the power button so no more turning off your phone by accident. Also there is an option to set the pin timeout a bit longer so you don’t have to type in your pin every time you want to use your phone (15 minutes is max when you have policies applied).

One small feature I didn’t read about but seems missing is setting up the mail sync times. On my old phone I used to sync mail automatically with push mail between 7:00 and 23:00 so my phone wouldn’t make so much noise when it’s next to my bed when I’m sleeping. I haven’t found this feature so I think this is a big miss for the Mango release.

 

More Social:

Facebook integration was already great in 7.0 but it just got even better. The threading functionality sounds great but for some reason with US/English and Dutch live accounts something doesn’t seem to work. I really can’t wait for this to start working because seeing this in the movies is so nice!

The “Me” live tile became a lot more useful in Mango because you can get messages in the tile about new updates you have on Facebook. also when clicking on the tile you can use Facebook check in with only a few finger presses.

The use of groups is also added in Mango but I haven’t used this yet. I can keep up with my social updates but maybe this will change when twitter will start working in the retail version of Windows Phone 7.1 (In the Mango Beta twitter integration is not yet available).

Other integration will also be available like LinkedIn but this doesn’t seem to work for me in the Beta either.

 

Dutch Language:

Up until now I only had the English language available which is ok if you only type in English. Since 50% of my communication is in Dutch I really enjoy the added Dutch dictionary added in Mango!

 

Bing!

Before Mango I can’t say I actually used the Bing button other then pressing it by accident. but now 4 new cool features are added that seem to work really good. One of the features that I was really looking forward to is “Bing Vision”. With Bing Vision you can scan barcodes, qr codes, text but also books, cd’s and dvd’s. When you can a book you can automatically open apps like amazon to order this book or get more info about the book. Really great!

 

Besides Bing Vision there is also a button to listen to music like Shazam did in 7.0. Now this feature is build in and is working pretty good. There is also a “Nearby” feature added to Bing to get nearby restaurants, things to see, hotspots etc but there is no Dutch content yet so I only get the nearest locations in Germany….

The last option that is added to Bing is the voice to text search. but I don’t really see the big use of this. when I tested it it made a lot of mistakes and in the same time I could write it.

 

IE9:

What can I say… the old browser in wp7 was a disaster. All other mobile browsers were far superior but now IE9 mobile uses the exact same rendering engine as the desktop version so it is a great improvement. It can render HTML5. has more screen space because the address bar is moved to the bottom (Would hope there would be an option to hide it though to get even more space when reading for example). also when browsing in landscape mode you can now use the address bar which wasn’t possible in 7.0.  You can now also pin websites to your homescreen for fast access to certain websites you use often.

 

7.1 apps:

I have seen a lot of movies and demo’s about cool apps using Mango features but there is no possibility to test those myself except for writing your own apps of course (which I will do!) I do have really high expectations about these apps and all the new features

 

To do:

One major issue a lot of people were missing are tasks but now this is added to your calendar hub and can be synced with exchange.

 

Games hub:

I’ve read a lot about new features in the games hub and the integration with Xbox live but since my Xbox Gamer tag live id is Dutch it’s not possible to use this yet. The list of games is cleaned up though and is looking a lot better than it did in 7.0

 

What is not in but needs to be in?

The one super major thing I really need is Tethering. I can understand not all providers can appreciate this feature but I used it on windows mobile 6.5 and now with the same provider I can’t use it anymore. that’s a bit shame!

the other thing I already mentioned and that is setting up times to sync your stuff and times it shouldn’t but it seems I’m the only one wanting this feature :(

Loads more is in!

Steve Balmer promised us 500 new features so I only touched on this a little but but I hope you enjoyed reading my first opinions about Mango and the Beta. I see a bright feature for WP7

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

Creating your own customizable tabs / carousel plugin for jQuery

Yesterday I was browsing the web for a tabs or carousel plugin for jQuery that fitted my needs. I wanted a simple but highly customizable control for displaying tabs which could also automatically page like a carousel. I found a lot of different plugins for JQuery but none fitted my exact needs. So I created my own in only 17 lines of javascript. this blog post describes how I did it and how you can use it on your website.

 

first of all of course is a demo. You can can check it here: http://www.vdcruijsen.net/demo/jquerycarousel/carouseldemo.html

so how does this work? We’ll start with the HTML used for the carousel:

<div id="carousel">

    <div class="carouselbody">

        <ul class="carouselcontainer">

            <li class="page"><div style="width:400px; height:300px; background-color:Green">test tab 1</div></li>                           

            <li class="page"><div style="width:400px; height:300px; background-color:Red">test tab 2</div></li>                           

            <li class="page"><div style="width:400px; height:300px; background-color:Orange">test tab 3</div></li>                           

            <li class="page"><div style="width:400px; height:300px; background-color:Blue">test tab 4</div></li>

        </ul>

    </div>

    <ul class="pager">

        <li><a class="pagerpage" href="#">&nbsp;</a></li>

        <li><a class="pagerpage" href="#">&nbsp;</a></li>

        <li><a class="pagerpage" href="#">&nbsp;</a></li>

        <li><a class="pagerpage" href="#">&nbsp;</a></li>

    </ul>

</div>

The HTML is actually pretty easy, The first div is a container with an id called carousel so the script knows what belongs to the carousel and what not. you can set a height and width on this div to size your carousel. The carousel div contains 2 main parts. the carouselbody a container for all the carousel pages and the pager where you can define your pager links. this pager can also be put before the carouselbody if you want the pager or tabs above your pages.

The carouselbody has a unordered list containing all the actual pages. all the list items are shown have a css class called page so the script knows that inside is the content for a page. in the list item I’ve put some div with inline styling to show that you can put whatever you want inside this page list item.

the pager has links which have a pagerpage class. the script will automatically match the first available pagerpage link to the first page etc.

Below is the css I used in the demo. you can customize this to set pictures for the paging mechanism or set heights, colors etc. this current css is just an example. (some display elements are needed though, its best to start of with the supplied css and change it to your likings.)

#carousel { height: 400px; overflow:hidden; }

#carousel .carouselbody { float: left; width: 400px; height: 360px; overflow: hidden; position: relative; background-color:#212020;}

#carousel .carouselcontainer { list-style: none; padding: 0px; margin: 0px;  position: absolute; left: 0; top: 0; }

#carousel .carouselcontainer li{ float: left; margin: 0px ; border-width: 0px;}

 

#carousel .pager { overflow:hidden; list-style: none; clear: both; }

#carousel .pager li { float: left; }

 

#carousel .page

{

    display:none;

}

 

#carousel .currentpage

{

    display:block;

}

 

#carousel .pagerpage

{

    margin-left:2px;

    background-image:url('/Content/images/pager2.png');

    width: 20px;

    height: 20px;

    display:block;

    text-decoration:none;

}

#carousel .currentpagerpage

{

    background-image:url('/Content/images/pager.png');

    text-decoration:none;

}

 

So now the HTML and CSS is explained its on to the actual jQuery script which makes all this magic happen. You only need 1 line to change a div to a working carousel if you also include the other script pieces somewhere on the page. the line to add in your script that is executed on document.ready is the following:

$("#carousel").carousel();

 

this method will of course only work if the carousel method is available. This is added through the following code:

$.fn.carousel = function (options) {

    var defaults = {

        start: 0

    };

    var options = $.extend(defaults, options);

 

    $(this).find(".page:eq(" + (options.start) + ")").addClass("currentpage");

    $(this).find(".pagerpage:eq(" + (options.start) + ")").addClass("currentpagerpage");

 

    $(this).find(".pagerpage").bind("click", function () {

        $(this).parents(".pager").find(".currentpagerpage").removeClass("currentpagerpage");

        $(this).parents("#carousel").find(".currentpage").removeClass("currentpage");

        $(this).addClass("currentpagerpage");

        var index = $(this).parent().index();

        $(this).parents("#carousel").find(".page:nth-child(" + (index + 1) + ")").addClass("currentpage");

    });

};

 

the $.fn.carousel line makes the carousel method available in the rest of your jQuery code. I’ve added some options as an example to make the carousel start at a different page.

the first thing the script does is searching for the page on which it should start and adds the currentpage css class to this page so the page becomes visible. The script does the same for the active pager item.

after this the script binds click events to the pager links so the pager links can do their work when they are clicked. on each click event the current page is made invisible by removing the currentpage css class and after it puts the current page css class on the newly selected page.. that’s all :)

 

Hopefully this code is something you can use on your own website or otherwise learn from it or use pieces of it.

 

Geert van der Cruijsen

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

Virtual conference MVCConf 2011

Yesterday MVCConf 2011 was held. MVCConf is a virtual conference about ASP.NET MVC and since ASP.NET MVC 3 has shipped a few weeks ago there was a lot to talk about. The conference is organized by the community and there are a lot of speakers from the Community as well as from Microsoft.

Some videos are online already at www.mvcconf.com/live but all videos are coming online later at the www.mvcconf.com site.

Since I’m an ASP.NET MVC fanatic I’ve used my free evening to watch the sessions and will view more tomorrow.

mvcconf

Sessions I watched:

Keynote by Scott Guthrie @scottgu

Scott talked about the history of ASP.NET MVC 3 and the older versions (ofcourse everyone knows he wrote version 1 during a single flight from his home to some conference a few years ago) and held an interactive session where people could ask questions using twitter. He talked about the difference of webforms and mvc ofcourse since this is a question that is always asked when talking about mvc on a high level. He noted again that webforms, webmatrix and MVC will all exist next to each other in the future and serve different purposes. to make this more clear he gave 3 keywords for all methods of building ASP.NET applications

WebMatrix

  • Simple
  • Light
  • Fast

Web Forms

  • Familiar
  • Reusable
  • Productive

MVC

  • Powerfull
  • Extensible
  • Agile

Other things he talked about is the focus of Microsoft on JQuery. Microsoft added JQuery to the MVC 1.0 and in 3.0 they even switched completely to JQuery when you look at all examples etc. Microsoft is also actively helping in creating a new JQuery plugin for the JQuery Datatable. this is something I would really like to see!!

Scott also told us about project Orchard which is a new open source CMS project by Microsoft. this is also looking really promising. Another thing Scott talked about really quick was an Asset management system for CSS and JS functions / snippets. more to come about this in the future. (he wasn’t supposed to say anything about this.)

Finally he talked about large sites running ASP.NET MVC. He couldn’t tell a lot about this since he didn’t know which company liked him saying their technology choices. but some examples he did tell were bing.com and other microsoft sites. other examples people on twitter added are the channel 9 site, stackoverflow.com and cheezburger.com :D

Phil Haack on nuget @haacked

Phil talked on Microsoft opensource project nuget by showing how you use it in visual studio using the extension manager and the console. I think most people have already seen and used nuget but this session went deeper. phil showed us how to create packages and how to use advanced functions the console. Something that was new to me he showed us is the local repository you can add in nuget. I’m going to have another look at this later so we can use it within our company.

after this he showed us how nuget is working under the hood. All in all a really nice session for me.

Brad Wilson on “Advanced MVC 3.0” @bradwilson

Brad talked on some advanced topics of MVC 3.0. It’s hard to do a recap on this one since it’s a lot of stuff. some things were really interesting. he started off with statefull filters to show how to use filters per request, per session or per applications. after this he talked about validation with unobstructive Ajax with Jquery. very interesting!!

He also talked about how to use different kinds of objects as classes for your model and about routing constraints.

If you are a more advanced MVC developer this is a session you shouldn’t miss.

Steve Sanderson on MVC Scaffolding @stevesanderson

Steve talked about the opensource project MVC Scaffolding. The original idea for this came from the Ruby community where people wanted to generate simple crud forms and the database itself from the model classes. Steve has created a package which you can get with nuget to have this in ASP.NET MVC 3.0.

Phil showed a quick sample of this on his nuget presentation and Steve also showed an example where he automatically generated everything using the repository pattern so you get a nice decoupled scenario without typing any code. after this he showed more complex situations. for more info check this blogpost:

http://blog.stevensanderson.com/2011/01/13/scaffold-your-aspnet-mvc-3-project-with-the-mvcscaffolding-package/

Other sessions I haven’t watched yet but will do later are:

BDD in ASP.NET MVC using SpecFlow, WatiN and WatiN Test Helpers by Brandon Satrom

Quality Driven Web Acceptance Testing by amir Barylko

WebMatrix by Rob Conery

Entity Framework “Code First”: Domain Driven CRUD by Chris Zavaleta

I really enjoyed the sessions. MVCConf and all speakers thanks and hopefully I’ll be able to join MVCConf 2012 again next year.

When all video’s are up I’ll edit the post with the links to the videos

Geert van der Cruijsen

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

Using the WP7 system color in live tiles and application icon

I’m currently building my first WP7 application for a contest that is held by Avanade Netherlands for all its employees. Who can create the best app in a small amount of time.

My app is almost finished and I was trying to set up the live tile and application icon. Of course I wanted to use the system color which the user has selected to display on the background of my live tile. How to do this? here is how, it is actually quite simple.

when you open your solution you’ll automatically get your background.png and applicationicon.png. both icons have a black/greyish background. like shown in the example below.

livetile1

to switch the background to use the system color follow the following steps:

  • Open up your background.png in any decent image editing tool like Paint.net.
  • Use the magic marker to select the background

live tile selected

  • press delete so you get a transparent background

 

live tile deleted

  • save the icon back to your visual studio solution.
  • compile
  • enjoy!

 

livetile2livetile3

 

Ofcourse the next step would be to do the same for your application icon (the icon in the application list).

I tried it and it didn’t work… after some research I found out that this is for Microsoft and official partners only.. Bummer!!

 

Guess we are going to be stuck by using greyish application icons after all.. hopefully Microsoft will fix this in the future.

 

Hopefully this post was helpful to you. In my opinion there are to few good resources to be found on WP7 development so every small thing helps.

Geert van der Cruijsen

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

First impression of the HTC Trophy and Windows Phone 7

A few weeks after the official release of windows phone 7 our entire company (Avanade Netherlands) moved to Windows phone 7. Every Employee (225) received a HTC Trophy today and tonight i’ve put my new phone to the test. Here are my first impressions:

the hardware:

The phone is feeling really robust and the screen is looking really well. the captative screen works very good aswell. all menus and buttons are reacting really fast and Microsoft really did their best in getting the UI right.. And they did! After testing the Camera i have to say that this is probably the worst part of this phone. when it’s a bit dark the pictures get really bad. i also don’t like the “hardware”/tip buttons under the screen. ofcourse you dont need them that much but when i compare this to my girlfriends HTC Desire i have to say i prefer real hardware buttons.

booting it for the first time:

after booting it you get a small tutorial to set stuff up. i choose to skip the windows live id and to just get started. within 1 minute my phone was ready to go. I’ve started setting up my exchange mail since all my contacts/mail/agenda stuff is in there. the setup was also done really easy, just add an exchange account, add your username/password and press ok. everything just worked. after this i’ve added my facebook account. after i did that all contacts were synced and merged perfectly. my exchange contacts have facebook pictures etc. looking pretty slick.

After this i tried setting up my live id.. stubborn as i am i ofcourse added my dutch liveid to see what would happen.. first it would ofcourse sync my mail/contacts etc.. that was the positive part. then i tried to open the marketplace but that wasn’t working. i tried to deinstall the live id but that isn’t possible. so a hard reset was a fact :D (within 5 minutes after i first touched it).

after playing with facebook/mail/apps etc i tried the most important thing a phone has to do: call someone. to make this extra hard i called someone while i was on my way home through my parrot carkit. some windows phone 6.5′s wouldnt even make this test but sound quality was really good with my new phone. also the ui of the call screen and contact screen  is really well thought off.

next try: setting up a US based live id and adding my dutch live id after. Perfect. i get all the contacts/agenda/mail from my dutch live id and i can get to the marketplace through my US live id.

ofcourse i had to set my facebook/exchange stuff again but that was done in a few minutes.

after playing around with it for a few hours this evening i have a pretty good feeling about this. my conclusions for now:

pro’s:

  • WP7 is really responsive and intuitive
  • overall hardware is robust and looking nice
  • everything just works (except dutch live id’s )
  • most important thing calling works really good (nice contact screen, nice call screen)

cons:

  • camera is a bit flaky
  • power charge is on the side of the phone (i am left handed and can’t even hold it normally when the power cable is in….)
  • Support for dutch marketplace / xbox live missing (will be there in april 2011)
  • no tethering (will come someday)

i’ll update some more about the new phone after i’ve played with it a bit more after a few days (battery use for example)

Geert van der Cruijsen

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

SharePoint Automatic prefilling of lookup fields in insert forms using JQuery

At my last project I was working on a SharePoint online solution and one of the requirements is to prefill some values at one of the insert forms for a list. Since this is SharePoint online and the only tool you can use to customize is SharePoint Designer I had to do this with JavaScript.

I’ll explain how to build it by an example. for example you have a list of customers and a list of customer actions. What I wanted to build was a way to make it easier to add a customer action for a specific customer. To do this I added a custom column to the customer list containing a link to the edit form with the customer id as an url variable. Of course the out of the box you can’t create links or any other html with calculated fields so I added more javascript there.

to enable html as output of a calculated field just copy this piece of javascript and put it in a content editor webpart or paste it on your master page.

var theTDs = document.getElementsByTagName("TD"); 

var i=0; 

var TDContent = " "; 

while (i < theTDs.length)

{ 

  try

  { 

    TDContent = theTDs[i].innerText || theTDs[i].textContent; 

    if ((TDContent.indexOf("<DIV") == 0) && (TDContent.indexOf("</DIV>") >= 0))

    { 

      theTDs[i].innerHTML = TDContent; 

    } 

  } 

  catch(err){} 

  i=i+1; 

} 

Thanks Marijn Somers for this piece of code. original source: http://marijnsomers.blogspot.com/2010/01/write-html-code-in-sharepoint-via.html

so now my calculated field was a link in html. what did my calculated field look like?

="<DIV><a href=’../../Lists/CustomerActions/NewForm.aspx?Customer="&[Customer ID]&"’>Add Customer Action</a></DIV>"

First a DIV element since the javascript above only replaces elements starting with a <DIV> to html, then just a plain html link to the NewForm.aspx sending the customer id as an url parameter.

 

So now the changes in the customer list are done and we only need to add some more javascript at the NewForm.aspx or again just at your masterpage to get the parameter from the url and selecting the right lookup field value at the form.

I’ve created the following code  using Jquery:

var customer = $.getUrlVar("Customer");

 

if(customer != "")

{

  $("input[title='Customer']").val(customer);

  

  $("select[title='Customer']").children("option").each(function() {

    if($(this).text() == customer)

    {

      $(this).attr('selected', 'selected'); 

    }

  });

}

My customer actions list contained a Customer field which is a lookup to the Customer list by Customer ID. The script above gets the Customer ID from the url parameters first and then tries to set the lookup item. SharePoint renders lookup items in 2 different ways. as a select box when there are less then +/- 25 items and as a auto complete textbox when there are more then 25 items in the lookup list. Because of that I firs try to set the textbox to the right value and after that the select. I’m using the title attribute to locate the right input field because it gets the same name as the field from SharePoint by itself.

Now when I open the newform.aspx?customer=1234 my customer lookup field is automatically prefilled with 1234

 

Geert van der Cruijsen

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

Using the SPContext in HttpModules in SharePoint

When you are building custom HttpModules in SharePoint a common thing to do is to use the SPContext object to get acces to your SPSite, SPWeb, SPList or SPListItem. When doing this you have to be careful because the SPContext isn’t available everywhere because HttpModules can run early in the ASP.Net request pipeline so the SPContext object isn’t available yet.

if you try to acces the SPContext to early in the pipeline you’ll get a System.InvalidOperationException error.

The earliest you can use the SPContext is in the “PreRequestHandlerExecute” so don’t use it at the BeginRequest event what most people try to use when they want to add code as early in the pipeline as possible

code:

   1: public class RequestHandlingHttpModule : IHttpModule, IRequiresSessionState

   2: {

   3:  

   4:     public void Dispose() {}

   5:  

   6:     public void Init(HttpApplication application)

   7:     {

   8:         application.BeginRequest += application_BeginRequest;

   9:         application.PreRequestHandlerExecute += new EventHandler(application_PreRequestHandlerExecute);

  10:     }

  11:  

  12:     void application_PreRequestHandlerExecute(object sender, EventArgs e)

  13:     {

  14:         string webUrl = SPContext.Current.Web.Url;

  15:     }

  16:  

  17:     void application_BeginRequest(object sender, EventArgs e)

  18:     {

  19:         // do not use SPContext here it will throw a System.InvalidOperationException 

  20:         // this event is fired before PreRequestHandlerExecute so code that doesn't uses SPContext goes here

  21:     }

  22:  

  23: }

Geert van der Cruijsen

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

Combined power of SharePoint and JQuery part 2: Changing the SharePoint webpart edit menu position

Have you ever had the problem using SharePoint 2007 that when you create small webpart zones that the edit button disappeared because the title of the webpart was to long? I ran into this problem at my current project and instead of shortening down the titles i came up with the idea of changing the position of the edit button to be on the left of the title. when the button is on the left and the title is on the right the title will be trimmed automatically since the webpart zones have a fixed length.

In your server side code it’s really hard to change these kinds of things because this is standard SharePoint functionality and you can’t change it server side. So the solution is to fix it using javascript and to make that easier I’m using JQuery.

first I’ll show you the results below and then how I did it using a small JQuery script.

before:

sharepointjquery1

after:

sharepointjquery2

Below is the JQuery script to change the position of the edit menu to the left. the only thing you have to do is save this code to a js file, include the reference to the js file and a reference to the JQuery library js file on your masterpage and you’re done.

   1: $(document).ready(function() {

   2:     SPEditMenuFix();

   3: });

   4:  

   5: function SPEditMenuFix() {

   6:     $(".ms-WPHeader").each(function() {

   7:         var first = $(this).children("td:first").clone(true);

   8:         var last = $(this).children("td:last").clone(true);

   9:         $(this).children("td:first").replaceWith(last);

  10:         $(this).children("td:last").replaceWith(first);

  11:     });

  12: }

Enjoy!

Geert van der Cruijsen

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

Updated my weblog to DotNetBlogengine 1.6.1

Just before my vacation to Peru i noticed that i received a lot of spam in my comments on my blog. i was running DotNetBlogEngine 1.4.5 and the spamfilter seemed to be broken. I didn’t have time to fix it before my vacation so i disabled comments for a while. now that I’m back I upgraded to 1.6.1 which has build in functionality for Askismet and Recaptcha.

because I had so many spam comments I had to remove all of them so sorry for everyone who posted real comments because they are also gone now.

BlogEngine.Net 1.6.1 (download from codeplex) feels like its a lot more mature then the 1.4.5 version I had before. Lets see how well it will go in the future.

Because of the switch I had to change the theme because the old one didn’t work that well with this new version so i downloaded a new theme from http://www.blogenginetheme.com/ and changed a bit to my liking. When i have time i’ll change it a bit more.

If you are still using an old version of BlogEngine.Net I would advise you to upgrade to 1.6.1 because it’s looking pretty good and upgrading was easy. (costed me 2 hours including deleting of spam Smile )

Enjoy my new weblog

Geert van der Cruijsen

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

Going to DevDays 2010

Wow first 7 months of no blogging then 2 in 1 week ;)

I’ve been looking through al the sessions on the first day of the DevDays 2010 at the world-forum The Hague, The Netherlands and I’ve picked the ones I’m going to.

devdays-logo 

First off starting with the Keynote of course by Anders Hejlsberg and the keynotes title is: “Trends and Future Directions in Programming Languages”.

After the keynote at 11:05 I’m going to see the session by Scott Hanselman called “ASP.NET MVC 2: Basics, Introduction”. Hopefully there are some new things for me to see although I know quite a bit about the MVC framework already :) If not… Scott is always a cool guy to listen to so i see no problems.

At 13:30 I’ll be going to the session by Alex Thissen called “Secure Coding”. It never hurts to know something about security :)

The next session at 15:05 is by Anders Hejlsberg again. The session is called “C# 4.0 and beyond”. I would really like to know what is beyond.

The last session of the DevDays at 16:40 I’m going to see is by Scott Hanselman. It’s called “ASP.NET MVC 2: Ninja Black Belt Tips”. Since I’m already a ASP.NET MVC ninja i would like to learn from the master how to get my black belt.

In the evening there are a couple of sessions at the “Geeknight”. The Geeknight sessions are sessions for the real geeks and are about programming for fun, home automation, etc.

Sessions at the Geeknight I’m going to are:

Ofcourse starting with the geeknight keynote by Tony Krijnen and Daniel van Soest at 18:30.

after the keynote “I’m going to learn how to make my blog suck less” by Scott Hanselman (wow 3 sessions on 1 day :) )

the last session at 21:00 is the hardest choice. i have to choose between “If the ‘Free Lunch’ is Over, Can we Still Afford to Eat? How to Power Boost your Applications “ or “Microcontrollers for .Net programmers” or “Using .NET to Program your Hobby Web-services”. I really don’t know what to expect from the first session, my interests aren’t with microcontrollers and the last session is about webservices which i do like but it’s a level 100 session and I think there isn’t going to be that much new stuff to be heard there.

so for now my choice is with “If the ‘Free Lunch’ is Over, Can we Still Afford to Eat? How to Power Boost your Applications “ by Rutger van Beusekom.

I really can’t wait for DevDays 2010 to start.

Maybe I’ll see you there!

Geert van der Cruijsen

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter