Monday, December 3, 2007

Sending SMS from PC using your GSM Mobile

If you have your GSM mobile phone connected with the PC, you can send SMS to any mobile from your PC.

Many mobile vendors like Samsung, Nokia etc. provide application for this purpose in the connectivity suite itself (which comes free with the mobile or can be downloaded from the vendor's website).

However, there are other mobile vendors which don't provide an software for this out of the box, like Sony Ericsson. But, you need not worry if your connectivity kit doesn't contain a software for sending SMS, because for this we have a good and free addon for Windows XP in the market from Microsoft which is called as "Microsoft SMS Sender".

Microsoft SMS Sender supports only SMS (and not MMS etc) over GSM networks (no CDMA/TDMA support). Though it has many limitations like this, it does the basic job of sending SMS nicely and the best part is that it can be used as a command line tool. It supports various command line switches and hence can be automated using the command line options. For details on command line options, refer to the documentation in the installation package.

Microsoft SMS Sender can be downloaded from here.

Friday, October 19, 2007

Upgrading existing ASP.NET project to AJAX Enabled Web Application

If you want to convert existing ASP.net web application to AJAX Enabled web application then it is as easy as just updating your existing project's web.config file, other than adding a new reference. But you need to take care of certain things otherwise this simple change might give you a tough time before you can actually start using new ASP.NET AJAX features in the existing application.

I am assuming that you have already installed ASP.NET AJAX 1.0 extension.

Following these simple steps first to add ASP.NET AJAX power to your application -

  • Open your existing application and add a new reference to 'System.Web.Extensions' assembly.
     
  • Now create a new ASP.NET AJAX enabled web application (we will use this new project to copy new settings to existing project).
     
  • Compare new application's web.config with your existing application's web.config.
     
  • Copy all new settings that you see in new project's web.config to existing application's web.config.

Now take care of certain things which might actually make your application behave weirdly while using ASP.NET AJAX features -

  • It is very important that if your existing application is still using Legacy XHTML conformance mode, then remove this declaration from your web.config -

    '<xhtmlConformance mode ="Legacy"/>'
     
  • If your application pages are still using non xhtml or old html DOCTYPE declaration then change it to use XHTML 1.0 (at least transitional) by using this declaration instead -

    "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">"
     
  • If after doing these changes, you face some issue with intellisense in Visual Studio then you will have to change the Tag Prefix for "System.Web.Extensions" assembly from 'asp' to anything else. For this locate this line in your application's web.config -

    "<add tagPrefix="ajax" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>"

     and replace the tagPrefix="asp" with tagPrefix="ajax" (or anything of your choice).

    Now instead of using <asp:ScriptManager> or <asp:UpdatePanel>, you will have to use this new prefix (like <ajax:ScriptManager>). But this hack will get back your Visual Studio's intellisense working.

If after all this you are still unable to upgrade your existing ASP.NET application to ASP.NET AJAX 1.0, please feel free to write to me. :)

Monday, July 30, 2007

ASP:GridView - making Pager always visible

You would have noticed this while implementing ASP.net GridView control that if the record count in the grid is lesser than the grid's page size, then the pager doesn't appear.

There can be times when you want the pager to be visible all the time (like when you implement custom paging). In such a case there is no property available in the grid which can directly let you do so. But, there is a workaround to make this happen.

To make this happen, you will have to do following -

1. Handle the GridView's PreRender event.
2. In the PreRender event, fetch the GridView's 'BottomPagerRow'
3. Set BottomPagerRow's 'Visible' property to 'True'.

Example :

Private Sub gvItems_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)Handles gvItems.PreRender

Dim gv As System.Web.UI.WebControls.GridView = CType(sender, System.Web.UI.WebControls.GridView)

    If Not gv Is Nothing Then

        Dim PagerRow As GridViewRow = gv.BottomPagerRow

        If Not PagerRow Is Nothing Then

            PagerRow.Visible = True

        End If

    End If

End Sub



Thats it!

Saturday, June 16, 2007

Using a Master Page in ASP.net

The easiest & quickest way to get on with Master Pages

Creating a Master Page :

  1. Create an aspx page, as you want the basic layout to be.
  2. Add a new Master Page to your web app.
  3. Copy all code from aspx page created in step 1, exclude @Page tag
  4. Paste everything by replacing default code in MasterPage, keep @Page tag as it is
  5. Wherever you want content to appear from content pages, place a <asp:contentplaceholder> control
  6. Master page is ready now
The above method helps in previewing changes easily, though a master page can be created directly without using an aspx page first, and can be previewed using a content page.

Using a Master Page :

  1. Add a WebContentForm to web app.
  2. if its a web project, you will have to select WebForm and check 'select master page' check box while adding this page.
  3. Select the master page for this page. That's it!
If a page already exist and you want to convert it to a content page, add "MasterPageFile" attribute in @Page directive of the wannabe content page and remove all html code from this page and pace <asp:content> control and the code you want to appear in content area.

Thursday, June 14, 2007

SQL Server Error : 'function_name' is not a recognized name

A silly issue, but may bug you if you are not a regular sql server udf user.

Whenever a scalar-valued user defined function is invoked just using the name of the function, single part, you will get an error like -

Msg 195, Level 15, State 10, Line 1
'function_name' is not a recognized function name.

To resolve this use at least two part function name (by prefixing it with owner).
example :
(1) Select MyScalarFunction() -- wrong usage
(2) Select dbo.MyScalarFunction() -- correct usage


Important thing to note is that table-valued function, unlike scalar-valued, can be called using single part name.

Tip: to avoid using multi part naming in sql server 2005, you can use synonyms.

[more reading on user defined functions]

Monday, June 11, 2007

Sending Email using .NET : FAQ

Sending an email using .NET is very easy and is just few lines of code. So not much of a trouble in coding it. But, actual problem starts when one tries to run it and specially on a new / non configured SMTP server. Debugging these few lines can make anyone go crazy as there is not much to do and can take days to be resolved.

Though we have a detailed documentation on MSDN and good examples, I would like to mention here another very good resource for FAQ on sending email - www.systemnetmail.com. This website hosts a detailed FAQ which you comes really handy while resolving email related issues.

In .NET 2.0, we use classes in System.Net.Mail namespace for this purpose and hence the name comes - 'systemnetmail.com'. For .NET 1.1 we had System.Web.Mail and, yes you guessed it, we have www.systemwebmail.com for referring to old style of sending email.

Overall, a nice and handy email FAQ compilation from Dave Wanta.

Friday, May 4, 2007

Background and Foreground Threads

In a multi-threaded application, it becomes very important to decide whether a thread will be a foreground thread or a background thread, specially if it is an unattended process, otherwise the program may continue to run even when it is not required.

Difference between the two is that a foreground thread runs until it is complete and does not allow the application or program to terminate before its termination. On the contrast, a background thread is immediately terminated whenever the application is terminated or all foreground threads belonging to the application are terminated.

In .NET we set a thread as a background thread or as a foreground thread by setting the property 'Thread.IsBackground' to true, for background, or false to indicate a foreground thread.

For example I have an applicaton that keeps a watch on my mailbox and alerts me whenever I receive a mail. For this purpose when the application starts, it starts a thread which keeps on polling to my mail server at a regular interval and checks for new mail. When I shut down this application, I would also want this thread to stop polling to the mail server. If this thread has been set as a background thread, it will be stopped automatically once I shut down the application. But, if this thread has been set as a foreground thread, then the application needs to have some logic in the method, which is running on this thread, to terminate when the application is requested to quit.

Monday, April 30, 2007

Spell Checker for HTML and ASP.NET pages

This is pretty old now, but I came across it few weeks back only. A fantastic add-on for Visual Studio, developed by Mikhail Arkhipov, the spell checker works in source view of HTML and ASP.NET design pages (aspx, ascx etc) and checks for spelling errors pretty intelligently.

It actually integrates MS Office 2003 spell checker with Visual Studio to do the job. Once installed, it is available in the 'Tools' menu in Visual Studio. When invoked from the menu, it checks the text and indicates spelling errors just like MS Word. However, it doesn't check for grammatical errors. It also provides suggestions for the correct word when the erroneous text is double clicked.

The best part is that by default it looks for text strings which will show up on the UI and excludes other tags, attributes and commands. However this can be customized further by using rules.

Read more about this on Mikhail's blog.

Yesterday, Mikhail has also published a multilingual edition of this tool. I have not evaluated this one yet, I am happy using English only :). So you let me know how that one works!
Find details about multilingual edition here.

Tuesday, March 13, 2007

MS SQL Server : The Game of Dynamic SQL

No matter how much we try to avoid dynamic sqls in our queries, there are times when we have no other choice than to use it. I have experienced that in general all programmers are not very well aware of the truths and myths related to dynamic sql queries and at times they end up implementing a solution that might not be the best one for their scenario.

I am not going to write about the truths and myths of dynamic sql here, but will point you to this article "The Curse and Blessings of Dynamic SQL" by Erland Sommarskog, which I came across long back. The article is very informative and is updated with latest changes in SQL Server. There are other articles from Erland on the same web and they are also equally informative and exhaustive. Also, there are other very useful links on the site that are related to SQL Server. A site - must to be in the 'favorites list' of any MS SQL programmer.

Friday, March 9, 2007

HTML Character Codes

Today I posted an article on the VB to C# blog about short circuiting in C# (read here). While previewing the post, I noticed that the pipe symbols are not appearing in the post. At first I thought that blogger should have converted it automatically to its HTML character code, but it didn't and they were just removed from the HTML. A search on Google took me to the complete dictionary of HTML Character Codes. Its really handy and helful for web developers. Its here!

Friday, March 2, 2007

New blog on Vb to C#

People, I have just started a new blog on common question that people from VB background ask when they start programming in C#. Read it at http://vbtocsharp.blogspot.com/. This is inspired by my personal experiences about moving to C# from VB.