Rami M. Nassar's Blog

Development, Beyound LifeStyle
Visual Studio 2011 IDE New Features, Search & Images Preview

Search

Visual Studio 2011 comes with very handy search feature in solution explorer. Find in solution explorer filters file list based on keyword you type in, and on the fly.
This feature will be available on New Project dialog, Tool Box, Solution Explorer, Parallel Watch and Error List. 

You just need to start typing the word, it will automatically filter the controls and files that matches with the text that you typed, either starts with or contains of your typed text.

I will leave you with screenshots:

 SearchSolutionExplorer

SearchNewProject

SearchToolbox

SearchErrorList

 

Images Preview

Other cool features that will be liked by developer, is the ability to preview any image file on the fly, you don’t have to click on the image file, just parse the cursor over the file name and it will show you the image as shown below on the screenshot:

PreviewImage

Happy Programming,
Rami M. Nassar

Nice IE6 Upgrade Warning!

The ie6-upgrade-warning is a little script (7.9kb) (download it from here) that displays a warning message politely informing the user to upgrade the browser to a newer version (links to newest IE, Firefox, Opera, Safari, Chrome are provided). The webpage is still visible behind a transparent background, but access to it is prevented. The idea is to force users to upgrade from IE6 and avoid the website from a bad reputation that website is not rendering correctly in IE6 (note: if you are a sharepoint developer, then you’ll be happy with this script). The script is completely translatable in any language, very easy to set-up (one line of code in webpage and one parameter configuration).

IE6 Warning

Just insert the lines

<!--[if lte IE 6]-->
<script src="js/ie6/warning.js"></script>
<script>window.onload=function(){e("js/ie6/")}</script>
<!--[endif]-->
 

  right after the <body> declaration of the webpage and change the e("js/ie6/") to the folder where the script's icons images are located.  

Happy Programming Winking smile
Rami M. Nassar

Posted: Jul 15 2011, 01:43 AM by rami_nassar | with no comments
Filed under:
Preview image file before upload to webserver

You can use javascript to preview the selected image before uploading it to the server.

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head id="Head1" runat="server"> 
    <title>Main Page</title> 
 
    <script type="text/javascript">         
     
        function FileUpload1_onchange(oFileUpload1) 
        {       
          document.getElementById('Image1').src = oFileUpload1.value ; 
        }         
         
    </script> 
 
</head> 
<body> 
    <form id="form1" runat="server"> 
        <asp:FileUpload ID="FileUpload1" runat="server" 
                 onchange="FileUpload1_onchange(this);"/> 
        <asp:Image ID="Image1" runat="server" /> 
    </form> 
</body> 
</html>


But due to security reasons, This doesn't work on some browsers. If this doesn't work for you, You'll have to save the image on some temporary location in server itself and preview it. You could try something like this :

 

.aspx

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head id="Head1" runat="server"> 
    <title>Main Page</title> 
 
    <script type="text/javascript">         
     
        function FileUpload1_onchange(oFileUpload1) 
        {       
          document.getElementById('btnPreviewImage').click() ; 
        }         
         
    </script> 
 
</head> 
<body> 
    <form id="form1" runat="server"> 
        <asp:FileUpload ID="FileUpload1" runat="server" 
            onchange="FileUpload1_onchange(this);" /> 
        <asp:Button ID="btnPreviewImage" runat="server" 
            Style="display: none;" OnClick="btnPreviewImage_Click" /> 
        <asp:Image ID="Image1" runat="server" /> 
    </form> 
</body> 
</html>

.aspx.cs

protected void btnPreviewImage_Click(object sender, EventArgs e) 
    { 
          if (FileUpload1.HasFile)   
         {   
             string path = Server.MapPath("TempImages");   
    
             FileInfo oFileInfo = new FileInfo(
                       FileUpload1.PostedFile.FileName);   
             string fileName = oFileInfo.Name;   
    
             string fullFileName = path + "\\" + fileName;   
             string imagePath = "TempImages/" + fileName;   
    
             if (!Directory.Exists(path))   
             {   
                 Directory.CreateDirectory(path);   
             }   
    
             FileUpload1.PostedFile.SaveAs(fullFileName);   
             Image1.ImageUrl = imagePath;   
         }   
    }

 

Happy Programming Smile
Rami M. Nassar

Facts About Gridview Events..
would like to share with you some facts about the Events fired in the GridView: ---------------------------------------------------------- RowCommand Is Fired BEFORE SelectedIndexChanging Is Fired BEFORE SelectedIndexChanged ----------------------------------------------------------- ---------------------------------------------------------- RowDeleting Is Fired BEFORE ObjectDataSource Delete Method Is Fired BEFORE RowDeleted ----------------------------------------------------------- ----------------------------------------------------------- The CommandName in: 1- ButtonField 2- CommandField 3- TemplateField containing a Button, LinkButton, ImageButton If set to: 1- Delete 2- Select 3- Insert 4- Edit 5- etc... The first method to fire is RowCommand before any other method. For example, if you have set OnRowDeleted, OnRowDeleting, OnRowCommand in the GridView on your page, the events are as follows: 1- RowCommand 2- OnRowDeleting 3- OnRowDeleted Hope the information above helps you out... Happy Programming :) Rami M. Nassar
Installing Team Foundation Server 2010 Beta 2

Just a few days ago  I decided to download and try Team Foundation Server (TFS) 2010 Beta 2  to see what’s new and to also figure out if this could be a good choice for a single developer that wants to use some source control for his personal projects without having to have a big (and expensive) server, which is usually just not affordable and time consuming.

In this post I’ll describe my experience installing TFS 2010 Beta 2 on my Windows 7 laptop. Please keep in mind that, at this point, I’m not a TFS 2010 expert at all.

To install Team Foundation Server (TFS) 2010 Beta 2 on Windows 7:

1. Download the TFS 2010 Beta 2 ISO image from here. You can burn it to a DVD, mount it to a virtual drive using your favorite ISO management software or just extract the contents to your hard disk using a common tool like Winzip.

2. Download the latest TFS 2010 Beta 2 Installation Guide from here (Recommended for future reference).

3. Start the installation using setup.exe which you will find in the TFS-x64 and TFS-x86 folder in the root of your installation media. Choose a folder depending on your computer architecture.

4. In the Welcome screen click Next.

TFSInstall01

5. In the license terms screen click Next.

TFSInstall02

6. In the feature selection screen select the features you want to install and the install location. Then click Install and wait for the installation to complete.

TFSInstall03

TFSInstall04

7. In the final installation screen make sure the Launch Team Foundation Server Configuration Tool checkbox is checked and then click Finish.

TFSInstall05

8. The Team Foundation Server Configuration Wizard will start now. Select Basic in the left panel of the wizard start screen and click Start Wizard.

TFSInstall06

9. In the TFS Basic Configuration Wizard start screen click Next.

TFSInstall07

10. In the SQL Server selection screen select SQL Server Express if you don’t have any SQL Server instance installed on your machine. Otherwise that option will be disabled and you can choose your SQL Server instance. Then click Next.

TFSInstall08

11.In the Configuration Settings Summary screen click Next.

TFSInstall09

12. In the Readiness Checks screen wait until your proposed configuration passes all validations and then click Configure.

TFSInstall10 

13. Wait until the wizard configures all required stuff and click Next.

TFSInstall11

14. Your TFS 2010 Beta 2 is now installed and configured. Click Close in the final screen to finish the configuration.

TFSInstall12

15. You can always check the details on your TFS configuration by going to the new Team Foundation Server Administration Console that you will find in Start Menu –> Microsoft Team Foundation Server 2010 Beta 2.

TFSInstall13

Some cool facts I loved during this installation are:

  • You no longer need a server OS for TFS. Your Windows 7 machine is just fine for the Basic configuration.
  • The installation is now separated from the configuration. You install the bits once and can configure/reconfigure TFS many times in the future. This will allow you to change your configuration depending on your future environment needs without performing a full installation each time.
  • The installation/configuration is very easy. You don’t need to worry about having IIS installed and configured appropriately, and the same applies for SQL Server. The wizard will take care of everything to make sure you go from zero to a complete TFS installation with only a few clicks.
  • You can now use SQL Server Express for your Basic configuration. The wizard will also install it if you don’t have it.
  • The Readiness Check is a huge time saving step. It will make sure your configuration will actually work before starting the configuration process. In previous versions you might need to wait until being in the middle of the installation process just to get an alert that tells you that you gave incorrect configuration data.

I’m already loving TFS 2010, and I have not even started to actually use it! I expect to write some more posts about my actual experience using it in my personal projects. So stay tuned!

Posted: Jan 24 2010, 05:18 PM by rami_nassar | with no comments |
Filed under:
HOW TO: Add a default ListItem to a DropDownList

This can be done one of 2 ways. A default ListItem can be added to a DropDownList programmatically with the following syntax after binding data to the DropDownList:

//Code here to populate DropDownList

DropDownListID.Items.Insert(0, new ListItem("Please Select One", "Default value")

 

This will add a ListItem to index 0, which will be the first ListItem.

In .NET 2.0, this can be done declaratively using the AppendDataBoundItems property. This will append all data-bound ListItems to the DropDownList, leaving those you add manually as the first selections.

<asp:DropDownList ID=DropDownListID AppendDataBoundItems=true runat=server>

<asp:ListItem Text=Please Select One Value=Default value />

</asp:DropDownList>

Benefits Of LINQ

Yesterday I was seeking for articles about benefits and advantages of LINQ technologies, and I found alot which I tried to mention them here (some of them I took from msdn forums)..

Benefits of LINQ:

1. Makes it easier to transform data into objects, meaning that LINQ reduces the amount of work you must do to translate between object-oriented code and data paradigms such as hierarchical, flat-file, messages, relational, and more. It doesn’t eliminate the “Impedence Mismatch” because you must still reason about your data in its native form, but the bridge from here to there is (IMO) much shorter.

2. A common syntax for all data. Once you learn query syntax, you can use it with any LINQ provider. I think this is a much better development paradigm than the Tower of Babel that has grown over the years with data access technologies. Of course, each LINQ provider has unique nuances that are necessary, but the basic approach and query syntax is the same.

3. Strongly typed code. The C# (or VB.NET) query syntax is part of the language and you code with C# types, which are translated into something a provider understands. This means that you gain the productivity of having your compiler find errors earlier in the development lifecycle than elsewhere. Granted, many errors in stored proc syntax will generate errors when you save, but LINQ is more general than SQL Server. You have to think of all the other types of data sources that generate runtime errors because their queries are formed with strings or some other loosely typed mechanism.

4. Provider integration. Pulling together data sources is very easy. For example, you can use LINQ to Objects, LINQ to SQL, and LINQ to XML together for some very sophisticated scenarios. I think it’s very elegant.

5. Reduction in work. Before LINQ, I spent a lot of time building DALs, but now my DataContext is the DAL. I’ve used OPFs too, but now I have LINQ that ships with multiple providers in the box and many other 3rd party providers, giving me the benefits from my previous points. I can set up a LINQ to SQL DataContext in a minute (as fast as my computer and IDE can keep up).

6. Performance in the general case doesn’t become an issue. SQL Server optimizes queries quite well these days, just like stored procs. Of course, there are still cases where stored procs are necessary for performance reasons. For example, I’ve found it smarter to use a stored proc when I had multiple interactions between tables with additional logic inside of a transaction. The communications overhead of trying to do the same task in code, in addition to getting the DTC involved in a distributed transaction made the choice for a stored proc more compelling. However, for a query that executes in a single statement, LINQ is my preferred choice because even if there was a small performance gain from a stored proc, the benefits in previous points (IMO) carry more weight.

7. Built-in security. One reason I preferred stored procs before LINQ was that they forced the use of parameters, helping to reduce SQL injection attacks. LINQ to SQL already parameterizes input, which is just as secure.

8. LINQ is declarative. A lot of attention is paid to working with LINQ to XML or LINQ to SQL, but LINQ to Objects is incredibly powerful. A typical example of LINQ to Objects is reading items from a string[]. However, that’s just a small example. If you think about all of the IEnumerable<T> collections (you can also query IEnumerable) that you work with every day, the opportunities are plentiful. i.e. Searching an ASP.NET ListBox control for selected items, performing set operations (such as Union) on two collections, or iterating through a List<T> and running a lambda in a ForEach of each item. Once you begin to think in LINQ, which is declarative in nature, you can find many of your tasks to be simpler and more intuitive than the imperative techniques you use today.

I could probably go on, but I’d better stop there. Hopefully, this will provide a more positive view of how you could be more productive with LINQ and perhaps see it as a useful technology from a broader perspective.

Happy Programming Smile
Rami M. Nassar

HOW TO: Merge Two Tables in One GridView
In a DataGrid we can show the data of a table easily. But if we want to show the data of two tables in a DataGrid then how we will show the data. For showing the data of two table in a single DataGrid we have to used the DataSet  merge property.
For showing the data of two table in a dataGrid make sure that the field name and field type of both table should be same.
 
The aspx code is:
 
<%@ Page Language=”C#” AutoEventWireup=”true”  CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml” >

<head runat=”server”>

    <title>Merge Two DataSet</title>

</head>

<body>

    <form id=”form1″ runat=”server”>

    <div>

      <table width=”70%” align=”center” border=”4″>

        <tr><td height=”20px”></td></tr>

        <tr><td align=”center”>

               <asp:DataGrid ID=”GridAllRecord” runat=”server” HeaderStyle-BackColor=”blue”>

               </asp:DataGrid>   

         <tr><td height=”20px”></td></tr>

         </td></tr>

      </table>  

    </div>

    </form>

</body>

</html>

 

 

The aspx.cs code
 

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Data.SqlClient;

 

public partial class _Default : System.Web.UI.Page

{

    SqlConnection con;

    SqlDataAdapter da;  

    DataSet ds1 = new DataSet();

    DataSet ds2 = new DataSet();

    protected void Page_Load(object sender, EventArgs e)

    {

        binddata();

    }

 

   public void binddata()

   {

       con=new SqlConnection(“Data Source=MCN101; Initial Catalog=MergeTable; Uid=sa; pwd=”);

       da = new SqlDataAdapter(“Select * from Table1″, con);

       da.Fill(ds1, “Record”);

       da = new SqlDataAdapter(“select * from Table2″, con);

       da.Fill(ds2, “Record”);

       ds1.Merge(ds2);

       GridAllRecord.DataSource = ds1;

       GridAllRecord.DataBind();

   } 

}

 

HOW TO: Accessing Config File Programmatically

The .NET Framework 2.0 provides APIs for accessing settings in a configuration file.
Here’s how you access the mail settings of a config file programmatically such as example…

C#

using System.Configuration;

using System.Web.Configuration;

using System.Net.Configuration;
 
Configuration configurationFile =

WebConfigurationManager.OpenWebConfiguration("PathToConfigFile");

MailSettingsSectionGroup mailSettings =

configurationFile.GetSectionGroup("system.net/mailSettings") as MailSettingsSectionGroup;

 if (mailSettings != null)

{

int port = mailSettings.Smtp.Network.Port;

string host = mailSettings.Smtp.Network.Host;

string password = mailSettings.Smtp.Network.Password;

string username = mailSettings.Smtp.Network.UserName;

}

VB.NET   

 

Imports System.Configuration

Imports System.Web.Configuration

Imports System.Net.Configuration  

Dim configurationFile As Configuration = WebConfigurationManager.OpenWebConfiguration("PathToConfigFile")

Dim mailSettings As MailSettingsSectionGroup = configurationFile.GetSectionGroup("system.net/mailSettings")

If Not mailSettings Is Nothing Then
	Dim port As Integer = mailSettings.Smtp.Network.Port
	Dim host As String = mailSettings.Smtp.Network.Host
	Dim password As String = mailSettings.Smtp.Network.Password
	Dim username As String = mailSettings.Smtp.Network.UserName
End If
More Posts