Thursday, February 23, 2012

Free Intro To JavaScript Book Online

If you need a easy to follow JavaScript into book and don't mind having to read it off your monitor screen you can check the free online version of Sams Teach Yourself JavaScript in 24 Hours.


Wednesday, September 14, 2011

Microsoft BUILD 2011 Keynote #1

Microsoft keynote featuring Steven Sinofsky, Mike Angiulo and Julie Larson-Green talking about Windows 8.

Wednesday, August 10, 2011

Android Tip: Enable a progress bar for a WebView

This is how you enable a progress bar when loading web pages using a WebView in Android:


final Activity activity = this;
     
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_PROGRESS);
        setContentView(R.layout.main);
     
       
        String url = "http://m.bing.com";

        WebView web = (WebView) findViewById(R.id.mainView);
             web.getSettings().setJavaScriptEnabled(true); 
             web.getSettings().setBuiltInZoomControls(true);
             web.getSettings().setUseWideViewPort(true);
              web.setWebChromeClient(new WebChromeClient() {
                  public void onProgressChanged(WebView view, int progress) {
                        activity.setProgress(progress * 100);
                  }
              });

             web.loadUrl(url);
       
    }

Note: requestFeature() must be call before any other content is added (call it right after super.onCreate).


Thursday, June 30, 2011

Mango Beta 2 for WP7 available for developers

I received an invitation to participate in the WP7's Mago 'Beta 2' program; unfortunately, I don't have a WP7 device (I use the emulator to develop). So, at least it seems that MS may be ready to roll out the first WP7.5 aka Mago phones by the end of the year.

Wednesday, June 1, 2011

How to connect to a SQL server database in c#

The following code snippet will show you how to query an SQL Server database in C# using ADO.NET.
Namespaces you will need to include:
using System.Data;
using System.Data.SqlClient;

Source Code:
SqlConnection conn = new SqlConnection("Data Source=Server Name;UID=User Name;PWD=Password;Initial Catalog=Database Name");
           SqlCommand command = new SqlCommand("SELECT TOP 100 * FROM  tbl_Users",conn);
           DataTable dt = new DataTable();

            command.Connection.Open();
           SqlDataAdapter adapter = new SqlDataAdapter(command);
           adapter.Fill(dt);

           adapter.Dispose();
           command.Connection.Close();
           command.Dispose();

           foreach (DataRow dr in dt.Rows)
           {
               Console.WriteLine(dr["FirstName"].ToString()+" "+dr["LastName"].ToString());
           }

Breakdown
Initialize a SqlConnection object by passing you server connection string as a parameter. Then, initialize a SqlCommand object which you can use it to execute a SQL query or a stored procedure (We passed the SqlConnection object as an additional parameter).  I will be retrieving a set of data from the sample query; so, I need either a DataSet or DataTable object to store the result. Next, we initialize a SqlDataAdapter object that will serve us as a bridge between the SqlCommand and the DataTable (we passed the SqlCommand object as a parameter). Finally, we simply open a connection and call the Fill() method to retrieve our result. 

Thursday, May 19, 2011

.NET Rocks Podcast

Software development podcasts are a great way to keep up with the always changing tech industry.

.NET Rocks Podcast is my favorite podcast about software development and not because I work with .NET but overall quality of the show is presented. The show is hosted by Carl Franklin and Richard Campbell; where they conducts a weekly interview to  industry experts such as Scott Guthrie and Billy Hollis.

To listen:

http://www.netcastia.com/dotNETRocks

or

http://www.dotnetrocks.com/

Tuesday, May 17, 2011

Remove read only attribute of a file in C#

To manipulate file attribute in C# we can use the System.IO.FileInfo class.
So, let’s say that we have a “Read Only” file located at C:\temp\test.jpg what we need to modify; however, we need to remove the “Read Only” attribute before we can continue.

Here is how to do it:

  FileInfo file = new FileInfo(@"C:\temp\test.jpg");
  file.Attributes = file.Attributes & ~FileAttributes.ReadOnly;

The above sample uses the bitwise operator in order to remove the “Read Only” attribute while ensuring that all other attributes that the file may have are not also removed during this operation.