@भि कहिन

my personal web log

Archive for the ‘Web Development’ Category

Office Web Apps

Posted by @bhitalks on June 11, 2010

Office Web Apps was up for evaluation for a long time when it was introduced as a Technical Preview along with Office 2010 to select participants. I received this news today…

Office Web Apps are now available for general public on Windows Live. The initial release is available to Windows Live customers in the USA, Canada, Great Britain and Ireland only. Later on by next week when MS Office 2010 is released, this will be extended to all customers.

Also, important news is that Office Web Apps will be available for free on Windows Live for general public starting two weeks from now!

Official announcement is here: http://blogs.msdn.com/b/officewebapps/archive/2010/06/07/10021218.aspx

I have been evaluating Office Web Apps for some time now. Here is a little screenshot walkthrough for you all:

clip_image002

When you log in to Windows Live (or SkyDrive), you see a new link called “New”, clicking which drops down to show a menu to create new Word, Excel, PowerPoint and OneNote documents. There are quick icons on the right too to do the same (but these icons are not visible always). You can also create/open a document in Office 2010 and then “Send to Web” using the “Share” option on “BackStage”, which will publish it to your SkyDrive account on Windows Live. The documents on SkyDrive can then be marked private or shared or public depending on how you want to share them. Co-Authoring is a new feature in Office 2010 and extends to Office Web Apps as well. This is in direct competition to share documents on Google Docs where multiple users can work on the same document from different places. But Microsoft Office Web Apps are far ahead!

clip_image004

Let’s see what happens when I click on the create new “Excel Workbook” menu option (as shown above)…

Windows Live asks for the filename to be given to the new document (notice that extension and hence version cannot be changed). Office Web Apps are limited to Office 2010 documents, however these documents are backward compatible with Office 2003 and Office 2007 by using document convertors.

Now once I give a filename (Sample.xlsx) in this case, it opens up the Excel Web App to edit and manage the document…

clip_image006

Notice how polished the interface is and how closely it resembles the Desktop version of Office 2010 including the “Ribbon Bar” and the “Backstage”! The application is very responsive and rightly so because it is based on Silverlight. Try looking at the source in Internet Explorer or use the Development Tools to inspect the DOM. You will find it very interesting and informative. The Excel Web App feels just like its desktop counterpart. Arrow keys work exactly the same, Double-click on column separator and column-autofit works exactly the same, F2 to edit a cell works and so do all keyboard shortcuts. Try entering a formula (although the sophisticated formula wizard is absent), but the auto-suggest works like a charm. (see the above screenshot). Notice the bottom-right corner where you will see how many people including you are currently working on this document. You may pull out presence information if you have Microsoft Live Communicator installed.

The backstage looks exactly same as its desktop counterpart, however the menu options are different to suit the web application…

clip_image008

Notice the above screenshot with “BackStage” open. There is no “Save” option! The documents are saved automatically!

It seems great as of now. Surely a Google Docs killer in my opinion. Do give it a try at least. You have to use it to believe it.

Okay, if you have seen the announcement, you must be aware that is open only for a few locations (USA, Canada, Great Britain and Ireland). It will still take some time before it opens out to all. If you have Office 2010 Beta or Trial version installed then you can start right away by sending your document to Web using the “Share” option on “BackStage”.

However, if you do not have Office 2010 (or for some reason unable to upload a document), then here is a little trick:

  1. Login to you Windows Live account at: http://windows.live.com or at http://skydrive.live.com
  2. Now once you are logged in, sign-up for the tech preview at: http://skydrive.live.com/acceptpreview.aspx/.documents?aobrp=browse
  3. This will add Office Web Apps to your live account and you can start creating and sharing your documents as shown in above screenshots.

So, if you haven’t already tasted it, do it now!

-@bhitalks

Posted in Web Development | 1 Comment »

Taming Date and Time formats in ASP.Net app ?

Posted by @bhitalks on March 4, 2010

 

You have this great web application being developed and you find yourself struggling with handling date/time data. Days and months have switched places, or even worse table columns have gone awry with width, trying to accommodate long dates instead of expected short format! And you start pulling your hair out of their roots trying to figure out whatever happened to the nice “01/03/2010” format, now showing as “Monday, March 1, 2010 11:15:26 PM”?

Am sure most of you must have at some point of time or other, struggled with taming dates in your ASP.Net application. Is yours a similar story? Let me consolidate here a few options of taming dates that I have learnt during my ordeals with such scenarios.

There are actually two parts to handle date/time formats. One while displaying on the webpage, and the other while trying to capture user input. Well, capturing user input is not the topic of discussion here because there are several calendar controls and other validation mechanisms in place always. So maybe a different post for that. Let’s see how we can control display of date/time data.

Scenario:

We want the date field to be displayed in “01-Mar-2010” format, so that there is no confusion. And yes, we are talking VB.Net here.

Option 1: The easiest way

Like an experienced trapeze artiste, do some acrobatics and put in a “Format” or “FormatDateTime” just before you are spitting out your date/time as a string.

dateString = FormatDateTime(dateField, DateFormat.ShortDate)

A “FormatDateTime” would be ideal, but the server’s culture may not be the format we need. Also, it needs a named format as its second parameter and so cannot be customized. So, do a “Format” instead.

dateString = Format(dateField, "dd-MMM-yyyy")

Ah that looks good. Fine go do that everywhere you are spitting out that date in your code. You have that at a hundred places? Go ahead do that, it is the easiest way. You have gridviews and other complex controls? Go ahead tap in the “RowDataBound” event and do something like this:

e.Row.Cells(4).Text = Format(DataBinder.Eval(e.Row.DataItem, "dateField"), "dd-MMM-yyyy")

Option 2: A little difficult way

Change your custom entity class to spit out a string instead of date. And then do a CDate whenever you need a date type in your code.

For example, for your customer class like this…

Class Customer
    Private _dateField As DateTime
    Public Property Datefield() As DateTime
        Get
            Return _dateField
        End Get
        Set(ByVal value As DateTime)
            _dateField = value
        End Set
    End Property
End Class

… change it to …

Class Customer
    Private _dateField As DateTime
    Public Property Datefield() As String
        Get
            Return Format(_dateField, "dd-MMM-yyyy")
        End Get
        Set(ByVal value As String)
            _dateField = CDate(value)
        End Set
    End Property
End Class

Notice the change in property. We are spitting out a string (formatted) and accepting a string which we convert to date just before assigning internally to our object.

So now you need not to worry. Everywhere in our code we will have a nicely formatted string, data-bound controls and all. You have a gridview bound to a List( Of Customer), nothing to change because the property is a string.

What? You do not have access to the entity layer? Or your controls are bound directly to the database (of course it is a small app, fine). Maybe, you do NOT want to change your code or perhaps you just can’t. Try out option #3.

Option 3: The most difficult part

We don’t know what culture the server follows. We don’t have access to that server anyway. So what we do is, we change the culture settings for our application.

We do that at the page level for any or all aspx pages:

<%@ Page Culture="hi-IN" Language="VB" %>

Or at the web.config level for the entire application (under system.web):

<system.web>
    <globalization culture="hi-IN"/>

Great, the above snippet shows that we changed the culture to Hindi-India. But, this will work only for named formats like ShortDate. Remember our discussion on Option 1 (FormatDateTime named formats) problem? We still do not have a control on this culture because we need a custom format.

So, now we add a little piece of code to our global.asax (inside the Application_BeginRequest handler)

Dim myCulture As CultureInfo
myCulture= CType(CurrentThread.CurrentCulture.Clone(), CultureInfo)
myCulture.DateTimeFormat.ShortDatePattern = "dd-MMM-yyyy"
myCulture.DateTimeFormat.DateSeparator = "-"
CurrentThread.CurrentCulture = myCulture

Don’t forget to add reference at the top:

Imports System.Globalization
Imports System.Threading.Thread

So what we are doing here is to implement a custom culture changing the date formats. In order to do this, we clone the current culture and change the required formats. Simple. Every time our application is requested, the culture gets customized. You don’t need to change anything elsewhere. No need to do “Format” or “FormatDateTime” scattered everywhere.

I haven’t touched on “Time” here, but as you can see it is the same. You can have it going yourself.

Hope that helps to ease your pain while dealing with date/time data in your web apps.

-@bhitalks

Posted in ASP.Net | Tagged: , , | 1 Comment »