Archives

Archives / 2008 / March
  • Calling a JavaScript function from Silverlight 2

    Wow, this is far better now with SL2! no more tips and tricks.

    JavaScript:

    <script type="text/javascript">
    function DisplayMessage()
    {
        alert("call me from Silverlight 2");
    }
    </script>

    Silverlight:

    using System.Web.Browser;
    
    HtmlPage.Window.CreateInstance("DisplayMessage");
  • [Cool Tool] PhotoZoom

    PhotoZoom is an experimental site developed at Microsoft, running on the Microsoft Live Labs Incubation Platform.

    It uses the Deep Zoom technology in Silverlight 2 to create photo albums that you can zoom an pan. This online app take care of processing the images, packages and uploads them to Silverlight Streaming by Windows Live so they are stored "in the cloud".

    Please note:

    • You need Silverlight 2 beta 1
    • This is not a final product
    • This may never be a product as is

    Check out live my Las Vegas photo Gallery:
    http://photozoom.mslivelabs.com/FullscreenZoom.aspx?alias=Laurent&album=1

    Disclaimer by Matt Augustine at Microsoft :
    "PhotoZoom is an experimental project developed by a small group of Microsoft developers, and it is definitely not an official, supported Microsoft product. Also, I cannot make any guarantees that it will be operational at all times, that it will support a large number of users, etc. This is not an official Microsoft press release and I am not a spokesperson. I can’t make any suggestions about future Microsoft product releases related to this technology or concept. In other words, I hope people will have fun with it, but please set your expectations accordingly."

  • Connect and share with Microsoft!

    Microsoft Connect has been improved! The new website is much more intuitive and interactive. "Your dashboard" view helps to keep an eye on your activities and news. I find the new Connect much more interesting than the old!

    What is Connect ?
    This is a way to help Microsoft improve their software by submitting feedback, bugs and filling surveys. Pick a program in the "Connection Directory" and start participate! Download the latest software and discuss your experience in the newsgroups.

     

  • Code snippets not versioned according to VS2008 Multi Targeting

    I have reported a VS2008 issue to the VS Team regarding code snippets :

    I am a heavy snippets user, and noticed that they are not tied to multi targeting...

    I use VS2008 with ASP.NET 2.0 websites (not migrated to ASP.NET 3.5), but snippets are for ASP.NET 3.5

    For example typing "prop" in C# code behind gives you:

    public int MyProperty { get; set; }

    Unfortunately this is not .NET 2.0...

    Suggestion: Built-in code snippets should be multi-targeting aware.

    The issue is visible and tracked in Connect:

    https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=331041

    I agree that the generated IL is the same, but the problem is when you work with VS2008 on the same project along with a VS2005 team...

    What do you think ?

     

  • My talk on MIX08 (french)

    This month I was a guest at the Visual Studio Talk Show, a well known french .NET podcast here in Quebec.

    We talked (in french...) about all the announcements (mainly IE8 and Silverlight) made at MIX this year, so in case you need a recap of this show...

    Les nouveautés de la conférence MIX 2008:
    http://www.visualstudiotalkshow.com/Archives/070-14mars2008-LaurentDuv.html

    Technorati Tags: ,,
  • Silverlight 2: migrating from alpha to beta 1

    Today I had to migrate a Silverlight Alpha 1.1 project to Silverlight 2 beta 1 for a client.

    As we had to expect there are a lot of changes!

    First thing to notice: after installing Silverlight 2 Tools for Visual Studio 2008 you won't be able to open your Silverlight 1.1 projects in VS2008, you have to migrate.

    The best way is to create a new Silverlight application and copy your old files there, then this article will be a huge help to fix your issues:
    MSDN: Breaking Changes in Silverlight 2
    http://msdn2.microsoft.com/en-us/library/cc189007(vs.95).aspx

    Here are some of the changes I had to deal with:

    • HtmlDocument.GetElementByID -> HtmlDocument.GetElementById
    • System.Windows.WebApplication.RegisterScriptableObject -> HtmlPage.RegisterScriptableObject
    • System.Windows.WebApplication -> System.Windows.Application
    • [Scriptable] attribute -> [ScriptableType] for class,  [ScriptableMember] for methods


    And the one who surprised me the most: Web Services

    It is said that you have to regenerate your Web Service client proxies, but when looking for "Add Web Reference" in VS2008, I don't find it!! I just have "Add Service Reference" which is WCF for me. For ASP.NET 3.5 projects, you have both "Add Service Reference" for WCF and "Add Web Reference" for Web Services.
    I know that Silverlight 2 supports both WCF and Web Services, so where the hell is "Add Web Reference" ??

    Answer is: use "Add Service Reference"!
    Calling a Web Service in Silverlight 2 is very similar to calling a WCF Service, that means that you have to specify binding and endpoint.

    Second surprise: all web service calls must be asynchronous!
    You must implement the async pattern, that surprised me at first, but now I found that this is not a bad thing and just requires 2 or 3 lines of code, so get used to it!

    For syntax and code details I invite you to read this very good post :
    Calling web services with Silverlight 2
    http://timheuer.com/blog/archive/2008/03/14/calling-web-services-with-silverlight-2.aspx

  • VS2008 and IE8 auto Js debugging mode

    Here is a nice feature of IE8:

    Remember both "Disable script debugging" options you had to uncheck in IE to enable JavaScript debugging ?

    image

    You no longer have to!

    You can now stay on default "script debugging off" mode in IE and when you hit F5 in VS2008, IE launch and the current tab is automatically set for debugging!

    [via Your Websites, Our Passion!]

    Also note that a slightly different version of the Internet Explorer Developer Toolbar is now built-in IE8, it is called the Developer Tools.

    IE is getting better for web developers, keep on, go ahead...

  • [Cool Tool] Browsershots

    Browsershots is a free online tool that makes screenshots of your web site in different browsers/versions on multiple platforms (Win, Mac, Linux).

    Use it to test the look of your web sites :
    http://browsershots.org/

    Set your choices then come back later and see the results (here you can see my blog before/after the Opera fix):

    On the live app you can click on a picture to get the full version.

    Note: IE8 is already available, but no Silverlight yet.

  • Fix my CSS, win a Prize!

    [Update: I have a Winner... contest closed!] 

    I was told that my blog does not display very well (or not at all) in Opera browser...

    Like most of you I don't have time for this, and community server's css are a real mess, so if someone takes time and send me the fixed css I will be happy to send him this DVD of Visual Studio 2008 Standard Edition (Full version with licence key) :

    So Paul Bidwell was the first to send me a fix:

    "/Themes/Blogs/marvin3/style/DynamicStyle.aspx?SectionID=559" Line 156:

    #sidebar-a {
    width: 200px !important;
    }

    Change the width to 199px;

    Also an img tag was no properly closed... (fool me!)

  • Blend 2.5 march preview: Where is the Silverlight DataGrid ??

    [Post written as of Silverlight 2 beta 1 and Expression Blend 2.5 march preview]

    Strange that the DataGrid is not in Expression Blend 2.5 march preview toolbox, but only in VS2008 !?

    If you add a DataGrid in VS2008 and then switch to Blend that will break your designer.
    It seems like there are problems with these assemblies references in Blend 2.5:

    System.Windows.Controls.dll
    System.Windows.Controls.Data.dll
    System.Windows.Controls.Extended.dll

    Remember that controls are not part of the runtime, they are part of the SDK and must be distributed with each application. Here are the different folders:

    • Runtime: "C:\Program Files\Microsoft Silverlight\2.0.30226.2"
    • SDK: "C:\Program Files\Microsoft SDKs\Silverlight\v2.0\Libraries\Client"

    Thanks to Michael Sync from the Silverlight forums, you can fix this:

    1. Fix the reference in Blend:
    Add reference to "System.Windows.Controls.Data.dll" from the SDK folder.

    2. Add this markup in <UserControl declaration:
    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"

    3. then, you can add a DataGrid like that:
    <data:DataGrid></data:DataGrid>

    Now you can find the DataGrid in Blend 2.5 Toolbox :

    1. Click on "Asset Library" (bottom of toolbox)
    2. Check "Show All"

     

  • Expression Web 2

    Back from MIX08 I've just installed Expression Studio 2 and my first try is Expression Web 2, not for the new features yet, but to check if my 2 most frustrating bugs were fixed, and they were!

    1. EW2 now remembers your credential when accessing remote web site... no need to type your ftp password again and again.

    2. Custom controls now works properly (IntelliSense, smart tag, toolbox), they broke the designer before, read: http://weblogs.asp.net/lduveau/archive/2007/11/18/expression-web-and-custom-controls.aspx.

    That's a good start!

  • [MIX08] Back to Montreal

    Due to major snow storm in Montreal area I spent 31 hours on my trip back from Las Vegas, finishing with a 11 hours bus ride from New York....

    Home Sweet Home.

    Two days ago I was burning in Death Valley (California)...

    Technorati Tags: ,

     

  • [MIX08] Sessions are available online (non Silverlight users banned)

    Not everything that happens in Vegas stays in Vegas...

    All sessions/keynotes can be viewed/downloaded at http://sessions.visitmix.com/.

    Note that this is a good example of a site using way too much Silverlight (you can't even do a copy/paste), but... seems that MS has a new toy to push !
    A non Silverlight alternative version would have been appreciated for people (like me) who can't install Silverlight on their company's computer.

    [Update] Luciano Evaristo Guerche has a nice MIX08 sessions list with WMV direct links!

    [Update] And now a nice Zune Podcast feed!

    Technorati Tags:
  • [MIX08] Keynote



    MIX08 Keynote was driven by Ray Ozzie, Scott Guthrie and Dean Hachamovitch.

    Ray Ozzie talked about connected apps and how Microsoft go to the advertising market (explains the Johnny cash theme ?).

    Scott Guthrie did a talk around 4 points (and also did some juggling!):

    • Web (IE8)
    • Media (Silverlight Adaptive Streaming, Progressive Download)
    • RIA (Silverlight 2, DeepZoom, WPF)
    • Mobile (Silverlight for Mobile)

    There was A LOT of announcements of new tools on web technologies:

  • Internet Explorer 8 Beta 1
  • Silverlight 2 Beta 1 Runtime
  • Silverlight 2 Tools for Visual Studio 2008 and SDK
  • Expression Studio 2 Beta
  • Expression Blend 2.5 March 2008 Preview
  • ASP.NET MVC Preview 2

    Once Silverlight 2 installed, go and test the new controls live there:
    http://silverlight.net/Samples/2b1/SilverlightControls/run/default.html

    Dean Hachamovitch (really cool shirt!) presented IE8 in 8 points:

    1. CSS2.1
    2. CSS Certification
    3. Performance
    4. HTML 5
    5. Developer Tools
    6. Activities
    7. WebSlices
    8. IE8 beta 1 available

    IE8 Activities and WebSlices video:


    First Look at IE8 Activities and WebSlices

    Then several partners (AOL, Aston Martin, Cirque du Soleil, DoubleClick, Hard Rock, Move Networks and NBCOlympics.com) showed some really cool demos on the new Web tools and technologies just announced.

     

  • ,
  • [MIX08] pre-conference day

    Today march 4 was the MIX08 VIP pre conference "Together@MIX". We had sessions and panels on the morning and an afternoon full of fun activities (I chose the Las Vegas Extreme rides!).

    Here is the speakers and a bit of what they said:

    Steve Guttman (PM for Expression Web)

    • Expression branding
    • Expression Web 2
      • PHP support (intellisense & syntax highlight, cassini for web server)
      • Photoshop layers support
      • ActiveX for Flash
      • AJAX
    • Expression Encoder 2 "a real post-production tool"
      • lots of new features
      • XAML and video overlays
      • Edit player in Blend
    • More at the keynote "I've been in Microsoft for years and the number of announcements at the keynote tomorrow is un-be-lie-vable !!"

    Doug Olson

    • Designer/Developer workflow
    • Expression Studio 2 for April (focus on Silverlight)
    • Expression Blend 2 (for Silverlight 1)
    • Expression Design (XAML slice like Dreamweaver)

    George Moore (GM Live Platform)

    • Live Messenger API
    • Silverlight Streaming
    • Audience Analytics

    Brad Abrams (ASP.NET Team)

    • Silverlight ASP.NET control
    • Silverlight Localization
    • Silverlight 2 UI controls
    • MVC sample app

    Tim Sneath

    • WPF
      • "WPF is the Ferrari, Silverlight is the Mini Cooper..."
      • Service Pack in september
      • Light .NET client install

    Daniel Makoski (Interactive Design Manager for Surface)

    • Microsoft Surface User Experience Team, or Microsoft Surface UX or Microsoft SUX...
    • Very funny video on Surface "Big Ass Table" !

    We had some keynote leaks today, but... let's wait for tomorrow !

    The afternoon was busy trying every roller coaster of Las Vegas !!!!

     

    Technorati Tags: ,
  • Load a txt file in a TextBox

    Here is a very simple piece of C# code to load a text file in a TextBox. Typical use to display a disclaimer

    [Update 1: added using statement for the StreamReader]

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            using (StreamReader StreamReader1 =
                new StreamReader(Server.MapPath("disclaimer.txt")))
            {
                txtDisclaimer.Text = StreamReader1.ReadToEnd();
                StreamReader1.Close();
            }
        }
    }

    [Update 2: use the new File.ReadAllText() wrapper for StreamReader, exact same thing, but 1 line of code instead of 3...]

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            txtDisclaimer.Text =
    File.ReadAllText(Server.MapPath("disclaimer.txt")); } }

    FYI here is the static ReadAllText method in Reflector:

    Then you could add a CheckBox to enable a Postback Button (disabled by default):

    <input id="cbAgree" type="checkbox" onclick="ManageBtnGoState();" />
    <label for="cbAgree" style="font-weight:bold; color:Red;">
    I Agree with the present statement</label>
    <asp:Button ID="btnGo" runat="server" Text="Take Survey"
    onclick="btnGo_Click" Enabled="false" />

    And the Js function:

    <script type="text/javascript">
    function ManageBtnGoState()
    {
        $get('<%= btnGo.ClientID %>').disabled = 'disabled';  
        if ( $get("cbAgree").checked == true )
        {    $get('<%= btnGo.ClientID %>').disabled = '';  }
    }
    </script>

    Note that $get() is a function from the ASP.NET AJAX client framework. If you don't have it please use document.getElementById() instead.

     

    Another solution

    Load the txt file from Resource.

    First add the text file as Resource in a resx file of your project (here common.resx):

     

    You can event have one file per language!


    Then the code looks like:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            txtDisclaimer.Text = Resources.Common.disclaimer_en;
        }
    }

    You could add a check for the current culture and load the corresponding disclaimer file.

  • [Cool Tool] VS Resource Refactoring Tool

    The recently opened Visual Studio Gallery contains some free hidden Microsoft gems, Resource Refactoring Tool is one of them.

    Resource Refactoring Tool provides developers an easy way to extract hard coded strings from the code to resource files. It works with C# and VB.Net in all project types that ships with Visual Studio 2005 and 2008.

    After installed, in code editor just click a string and select Refactor / Extract to Resource.

    A preview window shows changes, finds other instances of the text being replaced in the project, list existing similar resource items to avoid duplicate entries and automatically replaces hard coded string with a reference to the new resource item, nice!

     

    Resource Refactoring Tool Download link:
    http://www.visualstudiogallery.com/ExtensionDetails.aspx?ExtensionId=6ebe98b6-c344-4929-857c-6afebf51f4af