<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dot Net Thoughts &#187; Visual Studio</title>
	<atom:link href="http://www.dotnetthoughts.net/category/visual-studio/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotnetthoughts.net</link>
	<description>thoughts about .Net, WPF, Sharepoint, Javascript and more.</description>
	<lastBuildDate>Wed, 28 Jul 2010 09:59:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>.Net 4.0 and Visual Studio 2010 Released</title>
		<link>http://www.dotnetthoughts.net/2010/04/14/net-4-0-and-visual-studio-2010-released/</link>
		<comments>http://www.dotnetthoughts.net/2010/04/14/net-4-0-and-visual-studio-2010-released/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 07:26:25 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[VS2010]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=832</guid>
		<description><![CDATA[Download a full trial version at http://www.microsoft.com/visualstudio/en-us/download Free Visual Studio 2010 Express editions available at http://www.microsoft.com/express/downloads/ Free e-book &#8220;Moving to Visual Studio 2010&#8243; &#8211; Download from here http://www.microsoft.com/downloads/details.aspx?displaylang=en&#038;FamilyID=12a6de81-c633-4f2c-a35f-cea6fe772712]]></description>
			<content:encoded><![CDATA[<p>Download a full trial version at <a href="http://www.microsoft.com/visualstudio/en-us/download" target="_blank">http://www.microsoft.com/visualstudio/en-us/download</a></p>
<p>Free Visual Studio 2010 Express editions available at <a href="http://www.microsoft.com/express/downloads/" target="_blank">http://www.microsoft.com/express/downloads/</a></p>
<p>Free e-book &#8220;Moving to Visual Studio 2010&#8243; &#8211; Download from here <a target="_blank" href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&#038;FamilyID=12a6de81-c633-4f2c-a35f-cea6fe772712">http://www.microsoft.com/downloads/details.aspx?displaylang=en&#038;FamilyID=12a6de81-c633-4f2c-a35f-cea6fe772712</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2010/04/14/net-4-0-and-visual-studio-2010-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Exploring IL Assembler</title>
		<link>http://www.dotnetthoughts.net/2010/01/18/exploring-il-assembler/</link>
		<comments>http://www.dotnetthoughts.net/2010/01/18/exploring-il-assembler/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 17:56:20 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[IL]]></category>
		<category><![CDATA[ILASM]]></category>
		<category><![CDATA[ILDASM]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=726</guid>
		<description><![CDATA[One of colleague once asked a question to me, like what is the risk by distributing the windows application without obfuscating it. The only problem I found is user can use some tools like .Net Reflector and explore our assemblies. But few days before I found some nice .Net Framework tools, ildasm.exe and ilasm.exe, IL [...]]]></description>
			<content:encoded><![CDATA[<p>One of colleague once asked a question to me, like what is the risk by distributing the windows application without obfuscating it. The only problem I found is user can use some tools like .Net Reflector and explore our assemblies. But few days before I found some nice .Net Framework tools, ildasm.exe and ilasm.exe, IL Disassembler and IL Assembler respectively. These tools are available with .Net Framework SDKs. These tools can used to generate IL code for .Net assemblies and re-create assemblies from IL code. You can achieve it in code via .Net Reflection.Emit namespace. (In Community Techdays @ Cochin, one session is on Reflection.Emit. Don&#8217;t miss it.) As it is a vast topic I am only explaining basics <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><strong>Generate IL code using ILDASM.exe</strong></p>
<ol>
<li>First create a HelloWorld.cs and compile it to HelloWorld.exe</li>
<pre class="brush: csharp;">
using System;

public class HelloWorld
{
static int Main(string[] args)
	{
Console.WriteLine(&quot;Hello World&quot;);
		return(0);
	}
}
</pre>
<li>Use <code>csc.exe</code>to compile the cs file to exe. &#8211; <code>csc HelloWorld.cs</code></li>
<li>Use <code>ildasm.exe HelloWorld.Exe</code> to view the IL Code. You can find ILDASM in the Microsoft .Net SDK Path
<p><div id="attachment_724" class="wp-caption alignnone" style="width: 310px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2010/01/ildasm.png"><img class="size-medium wp-image-724" title="ILDASM - Exploring HelloWorld.exe " src="http://www.dotnetthoughts.net/wp-content/uploads/2010/01/ildasm-300x285.png" alt="ILDASM - Exploring HelloWorld.exe " width="300" height="285" /></a><p class="wp-caption-text">ILDASM - Exploring HelloWorld.exe </p></div></li>
<li>To generate the IL code use Select Dump option from File Menu or Press Ctrl+D. It will asks for a location to save the IL code.
<p><div id="attachment_722" class="wp-caption alignnone" style="width: 208px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2010/01/IL_Code1.png"><img class="size-full wp-image-722" title="IL Code Generated" src="http://www.dotnetthoughts.net/wp-content/uploads/2010/01/IL_Code1.png" alt="IL Code Generated" width="198" height="108" /></a><p class="wp-caption-text">IL Code Generated</p></div></li>
<li>Use any Editor to modify the IL code. You can find all the string values ( &#8220;Hello World&#8221; in this example ) as it is in the IL code. Modify it.( I am modifying it as &#8220;Hello World from IL Code&#8221;).
<p><div id="attachment_725" class="wp-caption alignnone" style="width: 310px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2010/01/Notepad_IL.png"><img class="size-medium wp-image-725" title="IL Code - Notepad" src="http://www.dotnetthoughts.net/wp-content/uploads/2010/01/Notepad_IL-300x150.png" alt="IL Code - Notepad" width="300" height="150" /></a><p class="wp-caption-text">IL Code - Notepad</p></div></li>
</ol>
<p>So we created the IL code and modified.<br />
<strong>Generate Assembly from IL code using ILASM.exe</strong></p>
<ol>
<li>Invoke the ILASM.exe with IL file as the parameter. <code>ilasm helloworld_il.il</code></li>
<li>It will show some details about assembling the IL code to assembly. And if the operation is successful you will get an exe in the location with HelloWorld_IL.exe.
<p><div id="attachment_723" class="wp-caption alignnone" style="width: 310px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2010/01/IL_Code3.png"><img class="size-medium wp-image-723" title="Assembling the IL code to EXE" src="http://www.dotnetthoughts.net/wp-content/uploads/2010/01/IL_Code3-300x151.png" alt="Assembling the IL code to EXE" width="300" height="151" /></a><p class="wp-caption-text">Assembling the IL code to EXE</p></div></li>
<li>If you invoke the exe from command prompt it will display the modified string instead of Hello World.(In this example &#8220;Hello World from IL Code&#8221;).</li>
</ol>
<p>You can do more if you know how IL works. Happy IL Programming <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2010/01/18/exploring-il-assembler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Implementing Custom Paging in DataRepeater using C# and SQL Server</title>
		<link>http://www.dotnetthoughts.net/2009/10/22/implementing-custom-paging-in-datarepeater-using-c-and-sql-server/</link>
		<comments>http://www.dotnetthoughts.net/2009/10/22/implementing-custom-paging-in-datarepeater-using-c-and-sql-server/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 14:40:23 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Databinding]]></category>
		<category><![CDATA[Repeater]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=558</guid>
		<description><![CDATA[Normally DataRepeater doesn&#8217;t have a paging feature; and you can implement it using LINQ, if you are using .Net 3.5. Here is an implementation which is using SQL Server 2005 feature ROW_NUMBER(). You can get more information about ROW_NUMBER() from MSDN. Stored Procedure &#8211; xsp_GetPersons CREATE PROCEDURE xsp_GetPersons @StartIndex INT, @Count INT AS BEGIN DECLARE [...]]]></description>
			<content:encoded><![CDATA[<p>Normally DataRepeater doesn&#8217;t have a paging feature; and you can implement it using LINQ, if you are using .Net 3.5. Here is an implementation which is using SQL Server 2005 feature ROW_NUMBER(). You can get more information about ROW_NUMBER() from <a href="http://msdn.microsoft.com/en-us/library/ms186734.aspx" target="_blank">MSDN</a>.</p>
<p>Stored Procedure &#8211; xsp_GetPersons</p>
<pre class="brush: sql;">
CREATE PROCEDURE xsp_GetPersons
@StartIndex INT, @Count INT
AS
BEGIN
DECLARE @EndIndex INT
SET @StartIndex = @StartIndex * @Count
SET @EndIndex = @StartIndex + @Count
SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY UserId DESC) AS SlNo, UserId, FirstName, LastName, Email, ISNULL(DOB, GETDATE()) AS DOB FROM U_MyRegistration)Registration WHERE Registration.SlNo BETWEEN @StartIndex AND @EndIndex
END
</pre>
<p>And I added a DataRepeater control, with Next and Previous buttons in the Footer.</p>
<pre class="brush: xml;">
&lt;tr&gt;
    &lt;td colspan=&quot;3&quot; align=&quot;left&quot;&gt;
        &lt;asp:LinkButton CommandName=&quot;Navigation&quot; CommandArgument=&quot;Prev&quot; runat=&quot;server&quot; ID=&quot;linkPrevious&quot;
            Text=&quot;&lt;&lt; Previous&quot; /&gt;
    &lt;/td&gt;
    &lt;td colspan=&quot;3&quot; align=&quot;right&quot;&gt;
        &lt;asp:LinkButton CommandName=&quot;Navigation&quot; CommandArgument=&quot;Next&quot; runat=&quot;server&quot; ID=&quot;linkNext&quot; Text=&quot;Next &gt;&gt;&quot; /&gt;
    &lt;/td&gt;
&lt;/tr&gt;
</pre>
<p>Code behind. As it is a sample code, I am not added any validations.</p>
<pre class="brush: csharp;">
int count = 10;
protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        BindData(); //Binding Data.
    }
}

private void BindData()
{
    int startIndex = Convert.ToInt32(this.hidCurrentIndex.Value);
    Persons p = new Persons();
    this.Repeater1.DataSource = null;
    this.Repeater1.DataSource = p.GetPersons(startIndex, count);
    this.Repeater1.DataBind();
}

protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    if (e.CommandName.Equals(&quot;Navigation&quot;,
StringComparison.CurrentCultureIgnoreCase))
    {
        if (e.CommandArgument.ToString().Equals(&quot;Prev&quot;,
StringComparison.CurrentCultureIgnoreCase))
        {
            this.hidCurrentIndex.Value = (Convert.ToInt32
(this.hidCurrentIndex.Value) - 1).ToString(); //Decrementing the count
            this.BindData();
        }
        else
        {
            this.hidCurrentIndex.Value = (Convert.ToInt32
(this.hidCurrentIndex.Value) + 1).ToString(); //Incrementing the count
            this.BindData();
        }
    }
}
</pre>
<p>And the implementation of Persons class from App_Code</p>
<pre class="brush: csharp;">
using System;
using System.Collections.Generic;
using System.Data.SqlClient;

public class Persons : List&lt;Persons.Person&gt;
{
    public class Person
    {
        public int UserId { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Email { get; set; }
        public DateTime DOB { get; set; }
    }

    public Persons GetPersons(int startIndex, int count)
    {
        Persons persons = new Persons();
        using (SqlConnection connection = new SqlConnection (&quot;Server=.\SQLEXPRESS;User Id=sa;Password=sapwd;Database=myDatabase&quot;))
        {
            connection.Open();
            using (SqlCommand command = new SqlCommand(&quot;xsp_GetPersons&quot;,

connection))
            {
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.Parameters.AddWithValue(&quot;@StartIndex&quot;, startIndex);
                command.Parameters.AddWithValue(&quot;@Count&quot;, count);
                SqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    persons.Add(new Person()
                    {
                        DOB = Convert.ToDateTime(reader[&quot;DOB&quot;].ToString()),
                        Email = reader[&quot;Email&quot;].ToString(),
                        FirstName = reader[&quot;FirstName&quot;].ToString(),
                        LastName = reader[&quot;LastName&quot;].ToString(),
                        UserId = Convert.ToInt32(reader[&quot;UserId&quot;].ToString()),
                    });
                }
            }
        }
        return persons;
    }
}
</pre>
<p>The core thing is stored procedure, which will return the results based on the given index. Thanks to <strong>Aneesh</strong> for the details of ROW_NUMBER() function.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2009/10/22/implementing-custom-paging-in-datarepeater-using-c-and-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TreeView Population without recursive function</title>
		<link>http://www.dotnetthoughts.net/2009/10/20/treeview-population-without-recursive-function/</link>
		<comments>http://www.dotnetthoughts.net/2009/10/20/treeview-population-without-recursive-function/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 14:42:56 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Common Table Expressions]]></category>
		<category><![CDATA[CTE]]></category>
		<category><![CDATA[Recursive function]]></category>
		<category><![CDATA[Treeview]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=544</guid>
		<description><![CDATA[If you want to display hierarchical data in a Treeview normally we are using recursion. I was looking for code which helps to avoid recursion using a Single query. But that code was using VB.Net and it was using a class called &#8220;Collection&#8221;, which is not available in C#. So I was looking for a [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to display hierarchical data in a Treeview normally we are using recursion. I was looking for code which helps to avoid recursion using a Single query. But that code was using VB.Net and it was using a class called &#8220;Collection&#8221;, which is not available in C#. So I was looking for a compatable code in C# for long time and today I got the chance to re-write it using C#, but I am using Lamda expressions for this.</p>
<p>Here is the Table structure I want to display in Treeview</p>
<pre class="brush: sql;">

CREATE TABLE [dbo].[tblEmployees](
[EmployeeId] [int] IDENTITY(1,1) NOT NULL,
[EmployeeName] [nvarchar](50) NOT NULL,
[Parent] [int] NOT NULL)
</pre>
<p>And I inserted following Data in it.</p>
<div id="attachment_545" class="wp-caption alignnone" style="width: 299px"><img src="http://www.dotnetthoughts.net/wp-content/uploads/2009/10/Table_Data.JPG" alt="Table Data" title="Table Data" width="289" height="383" class="size-full wp-image-545" /><p class="wp-caption-text">Table Data</p></div>
<p>And the Stored Procedure for getting employees using Common Table Expressions.</p>
<pre class="brush: sql;">
-- usp_GetEmployees
CREATE PROCEDURE [dbo].[usp_GetEmployees]
AS
BEGIN
	WITH SimpleRecursive AS
	(SELECT EmployeeName, EmployeeId, Parent, 0 AS Depth FROM dbo.tblEmployees
	WHERE (EmployeeId IN(SELECT EmployeeId FROM dbo.tblEmployees AS Recursion1
	WHERE (Parent = 0)))
	UNION ALL
	SELECT P.EmployeeName, P.EmployeeId,P.Parent, A.Depth + 1 AS Depth
	FROM dbo.tblEmployees AS P INNER JOIN SimpleRecursive AS A ON A.EmployeeId = P.Parent)
	SELECT EmployeeName, EmployeeId, CONVERT(INT, Parent) AS Parent, Depth
	FROM SimpleRecursive AS SimpleRecursive_1
	ORDER BY Depth
END
</pre>
<p>And the code in C# which adding nodes to Treeview.</p>
<pre class="brush: csharp;">
private void PopulateTreeview()
{
    this.tvEmployees.Nodes.Clear();
    Employees employees = new Employees();
    using (SqlConnection connection = new SqlConnection(@&quot;Server=.\SQLEXPRESS; User Id=SQLUser;Password=SQLPassword;Database=Database&quot;))
    {
        connection.Open();
        using (SqlCommand command = new SqlCommand(&quot;usp_GetEmployees&quot;, connection))
        {
            command.CommandType = System.Data.CommandType.StoredProcedure;
            SqlDataReader reader = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
            while (reader.Read())
            {
                employees.Add(new Employees.Employee()
                {
                    Depth = int.Parse(reader[&quot;depth&quot;].ToString()),
                    EmployeeId = int.Parse(reader[&quot;EmployeeId&quot;].ToString()),
                    Parent = int.Parse(reader[&quot;Parent&quot;].ToString()),
                    EmployeeName = reader[&quot;EmployeeName&quot;].ToString(),
                });
            }
        }
    }

    foreach (Employees.Employee employee in employees)
    {
        Employees.Employee parentEmp = employees.Find(o =&gt; o.EmployeeId == employee.Parent);
        if (parentEmp != null)
        {
            this.tvEmployees.Nodes.Find(parentEmp.EmployeeId.ToString(), true)[0].Nodes.Add(employee.EmployeeId.ToString(), employee.EmployeeName);
        }
        else
        {
            this.tvEmployees.Nodes.Add(employee.EmployeeId.ToString(), employee.EmployeeName);
        }
    }
    this.tvEmployees.ExpandAll();
}
</pre>
<p>And the employees class </p>
<pre class="brush: csharp;">
public class Employees : List&lt;Employees.Employee&gt;
{
    public class Employee
    {
        public int EmployeeId
        {
            get;
            set;
        }
        public string EmployeeName
        {
            get;
            set;
        }
        public int Parent
        {
            get;
            set;
        }
        public int Depth
        {
            get;
            set;
        }
    }
}
</pre>
<p>And here is the screenshot</p>
<p><div id="attachment_551" class="wp-caption alignnone" style="width: 345px"><img src="http://www.dotnetthoughts.net/wp-content/uploads/2009/10/treeview_Demo.JPG" alt="Treeview Demo - Screenshot" title="Treeview Demo - Screenshot" width="335" height="447" class="size-full wp-image-551" /><p class="wp-caption-text">Treeview Demo - Screenshot</p></div><br />
Thanks to <strong>Aneesh</strong> and <strong>Anas</strong> for their valuable comments.<br />
Happy Programming <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2009/10/20/treeview-population-without-recursive-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Application development using Gtk# in .Net</title>
		<link>http://www.dotnetthoughts.net/2009/10/17/application-development-using-gtk-in-net/</link>
		<comments>http://www.dotnetthoughts.net/2009/10/17/application-development-using-gtk-in-net/#comments</comments>
		<pubDate>Sun, 18 Oct 2009 02:53:04 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Gtk]]></category>
		<category><![CDATA[Mono]]></category>
		<category><![CDATA[VB.Net]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=532</guid>
		<description><![CDATA[When I started my software development career, I got introduced to some cool tools for GUI application development in Linux. I was using Glade and the library was Gtk. Then later I become a MS fan and started working on ASP, VB and .Net. Yesterday I got a chance to download Mono and Monodevelop. And [...]]]></description>
			<content:encoded><![CDATA[<p>When I started my software development career, I got introduced to some cool tools for GUI application development in Linux. I was using Glade and the library was Gtk. Then later I become a MS fan and started working on ASP, VB and .Net. Yesterday I got a chance to download Mono and Monodevelop. And the Gtk for Windows and .Net called Gtk#. I explored in Mono Develop(I was downloaded MonoDevelop-2.2 beta 2) a little, but it was crashed for me two time. <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  Then I started using Gtk# in VC# Express. And I created a simple Text File Viewer using C#, with Gtk# for UI. Most of the things in Gtk# is pretty different from .Net Windows Forms development. And I like the concept to in built support for predefined MenuItems, Icons etc. I think MS took the idea of commands in WPF from this.</p>
<p>I created a Windows Application Project and Added reference of the following libraries</p>
<p>atk-sharp.dll<br />
gdk-sharp.dll<br />
glade-sharp.dll<br />
glib-sharp.dll<br />
gtk-dotnet.dll<br />
gtk-sharp.dll</p>
<p>And I deleted the Form1. And modified the Program.cs; the Program.cs</p>
<pre class="brush: csharp;">
namespace HelloGtk
{
    using System;
    using Gtk;

    public class Program
    {
        private MainWindow mainWindow = null;

        public Program()
        {
            Application.Init();
            mainWindow = new MainWindow();
            Application.Run();
        }

        static void Main()
        {
            new Program();
            return;
        }
    }
}
</pre>
<p>And the added a class MainWindow.cs, and wrote the code</p>
<pre class="brush: csharp;">
namespace HelloGtk
{
    using Gtk;
    using System.IO;

    public class MainWindow : Gtk.Window
    {
        private string title = &quot;Text File Viewer&quot;;
        private VBox vbox;
        private MenuBar menubar;
        private Statusbar statusbar;
        private TextView textView;
        private ScrolledWindow scrolledWindow;
        private AccelGroup accelGroup;
        private Toolbar toolbar;
        public MainWindow()
            : base(&quot;Text File Viewer&quot;)
        {
            this.DefaultSize = new Gdk.Size(600, 500);
            this.DeleteEvent += new DeleteEventHandler(MainWindow_DeleteEvent);
            this.Build();
        }

        private void MainWindow_DeleteEvent(object o, DeleteEventArgs args)
        {
            Application.Quit();
            args.RetVal = true;
        }

        private void Build()
        {
            this.Title = this.title;
            this.vbox = new VBox(false, 0);
            this.CreateMenubar();
            this.vbox.PackStart(this.menubar, false, true, 0);
            this.toolbar = new Toolbar();
            this.CreateToolbar();
            this.vbox.PackStart(this.toolbar, false, true, 0);
            this.textView = new TextView();
            this.textView.Editable = false;
            this.textView.WrapMode = WrapMode.Word;
            this.scrolledWindow = new ScrolledWindow();
            this.scrolledWindow.SetPolicy(PolicyType.Automatic, PolicyType.Automatic);
            this.scrolledWindow.Add(this.textView);
            this.vbox.PackStart(this.scrolledWindow, true, true, 0);
            this.statusbar = new Statusbar();
            this.vbox.PackStart(this.statusbar, false, true, 0);
            this.Add(this.vbox);
            this.ShowAll();
        }
        private void CreateToolbar()
        {
            ToolButton OpenToolBarBtn = new ToolButton(&quot;gtk-open&quot;);
            OpenToolBarBtn.Clicked += this.openMenu_Activated;
            SeparatorToolItem Sep1 = new SeparatorToolItem();
            ToolButton CopyToolBarBtn = new ToolButton(&quot;gtk-copy&quot;);
            CopyToolBarBtn.Clicked += this.copyMenu_Activated;
            SeparatorToolItem Sep2 = new SeparatorToolItem();
            ToolButton AboutToolBarBtn = new ToolButton(&quot;gtk-about&quot;);
            AboutToolBarBtn.Clicked += this.aboutMenu_Activated;

            this.toolbar.Add(OpenToolBarBtn);
            this.toolbar.Add(Sep1);
            this.toolbar.Add(CopyToolBarBtn);
            this.toolbar.Add(Sep2);
            this.toolbar.Add(AboutToolBarBtn);
        }

        private void CreateMenubar()
        {
            this.accelGroup = new AccelGroup();
            this.menubar = new MenuBar();
            MenuItem fileMenu = new MenuItem(&quot;_File&quot;);
            MenuItem editMenu = new MenuItem(&quot;_Edit&quot;);
            MenuItem helpMenu = new MenuItem(&quot;_Help&quot;);
            helpMenu.RightJustified = true;

            Menu fileSubMenu = new Menu();
            TearoffMenuItem fileMenuTearOff = new TearoffMenuItem();
            ImageMenuItem openMenu = new ImageMenuItem(&quot;gtk-open&quot;, accelGroup);
            openMenu.Activated += new System.EventHandler(openMenu_Activated);
            SeparatorMenuItem fileMenuSep = new SeparatorMenuItem();
            ImageMenuItem exitMenu = new ImageMenuItem(&quot;gtk-quit&quot;, accelGroup);
            exitMenu.Activated += new System.EventHandler(exitMenu_Activated);
            fileSubMenu.Add(fileMenuTearOff);
            fileSubMenu.Add(openMenu);
            fileSubMenu.Add(fileMenuSep);
            fileSubMenu.Add(exitMenu);
            fileMenu.Submenu = fileSubMenu;

            Menu editSubMenu = new Menu();
            ImageMenuItem copyMenu = new ImageMenuItem(&quot;gtk-copy&quot;, accelGroup);
            copyMenu.Activated += new System.EventHandler(copyMenu_Activated);
            TearoffMenuItem editMenuTearOff = new TearoffMenuItem();
            editSubMenu.Add(editMenuTearOff);
            editSubMenu.Add(copyMenu);
            editMenu.Submenu = editSubMenu;

            Menu helpSubMenu = new Menu();
            ImageMenuItem aboutMenu = new ImageMenuItem(&quot;gtk-about&quot;, accelGroup);
            TearoffMenuItem helpMenuTearOff = new TearoffMenuItem();
            helpSubMenu.Add(helpMenuTearOff);
            helpSubMenu.Add(aboutMenu);
            aboutMenu.Activated += new System.EventHandler(aboutMenu_Activated);
            helpMenu.Submenu = helpSubMenu;

            this.menubar.Add(fileMenu);
            this.menubar.Add(editMenu);
            this.menubar.Add(helpMenu);
        }

        void aboutMenu_Activated(object sender, System.EventArgs e)
        {
            using (Dialog dialog = new MessageDialog(this,
                                  DialogFlags.Modal | DialogFlags.DestroyWithParent,
                                  MessageType.Info,
                                  ButtonsType.Ok,
                                  &quot;Text File Viewer - A simple text file viewer using gtk#\nDeveloped by Anuraj\nPowered by dotnetthoughts.net\n\nUnder GNU GPL v2.&quot;))
            {
                dialog.Title = &quot;About&quot;;
                dialog.Run();
                dialog.Hide();
            }
        }

        private void copyMenu_Activated(object sender, System.EventArgs e)
        {
            Clipboard clipboad = this.textView.GetClipboard(Gdk.Selection.Clipboard);
            this.textView.Buffer.CopyClipboard(clipboad);
        }

        void exitMenu_Activated(object sender, System.EventArgs e)
        {
            Application.Quit();
        }
        FileChooserDialog dlg;
        private void openMenu_Activated(object sender, System.EventArgs e)
        {
            dlg =
                new FileChooserDialog(&quot;Select Text File&quot;, this, FileChooserAction.Open, &quot;&quot;);
            dlg.AddButton(&quot;Open File&quot;, ResponseType.Ok);
            dlg.AddButton(&quot;Cancel&quot;, ResponseType.Cancel);

            FileFilter filter = new FileFilter();
            filter.AddPattern(&quot;*.txt&quot;);
            filter.AddPattern(&quot;*.*&quot;);
            dlg.Filter = filter;

            dlg.TypeHint = Gdk.WindowTypeHint.Dialog;
            dlg.SelectMultiple = false;
            dlg.WindowPosition = WindowPosition.Center;
            dlg.Parent = this;
            dlg.Modal = true;
            dlg.KeepAbove = true;
            dlg.DestroyWithParent = true;
            dlg.State = StateType.Normal;

            dlg.Response += new ResponseHandler(dlg_Response);
            dlg.DeleteEvent += new DeleteEventHandler(dlg_DeleteEvent);

            dlg.Run();
            dlg.Destroy();

        }

        private void dlg_DeleteEvent(object o, DeleteEventArgs args)
        {
            dlg.Destroy();
        }

        private void dlg_Response(object o, ResponseArgs args)
        {
            if (args.ResponseId == ResponseType.Ok)
            {
                this.Title = string.Format(&quot;{0} - {1}&quot;, this.title, System.IO.Path.GetFileName(dlg.Filename));
                using (StreamReader reader = new StreamReader(dlg.Filename, true))
                {
                    this.textView.Buffer.Text = reader.ReadToEnd();
                }
            }
            dlg.Destroy();
        }
    }
}
</pre>
<p>And run the application. Here is the screenshot, Text File Viewer running on my machine.</p>
<div id="attachment_541" class="wp-caption alignnone" style="width: 510px"><img src="http://www.dotnetthoughts.net/wp-content/uploads/2009/10/Text_File_Viewer_Using_GTK.jpg" alt="Text File Viewer using GTK#" title="Text File Viewer using GTK#" width="500" height="326" class="size-full wp-image-541" /><p class="wp-caption-text">Text File Viewer using GTK#</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2009/10/17/application-development-using-gtk-in-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to check remote file exists using C#</title>
		<link>http://www.dotnetthoughts.net/2009/10/14/how-to-check-remote-file-exists-using-c/</link>
		<comments>http://www.dotnetthoughts.net/2009/10/14/how-to-check-remote-file-exists-using-c/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 06:49:25 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[File Existance]]></category>
		<category><![CDATA[Remote File exists]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[Windows Forms]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=493</guid>
		<description><![CDATA[Sometime you require to display remote images in the Web Pages, like Ads, Banner etc, it may be from different domain or a different application. This code will help you to check the existence of a Remote file using C#. using System.Net; /// /// Checks the file exists or not. /// /// The URL of [...]]]></description>
			<content:encoded><![CDATA[<p>Sometime you require to display remote images in the Web Pages, like Ads, Banner etc, it may be from different domain or a different application. This code will help you to check the existence of a Remote file using C#.</p>
<pre class="brush: csharp;">
using System.Net;

///
/// Checks the file exists or not.
///
/// The URL of the remote file.
/// True : If the file exits, False if file not exists
private bool RemoteFileExists(string url)
{
    try
    {
        //Creating the HttpWebRequest
        HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
        //Setting the Request method HEAD, you can also use GET too.
        request.Method = &quot;HEAD&quot;;
        //Getting the Web Response.
        HttpWebResponse response = request.GetResponse() as HttpWebResponse;
        //Returns TURE if the Status code == 200
        return (response.StatusCode == HttpStatusCode.OK);
    }
    catch
    {
        //Any exception will returns false.
        return false;
    }
}
</pre>
<p>You can also use WebClient class for the same purpose. Like this.</p>
<pre class="brush: csharp;">
using System.Net;

///
/// Checks the file exists or not.
///
/// The URL of the remote file.
/// True : If the file exits, False if file not exists
private bool RemoteFileExists(string url)
{
    bool result = false;
    using (WebClient client = new WebClient())
    {
        try
        {
            Stream stream = client.OpenRead(url);
            if (stream != null)
            {
                result = true;
            }
            else
            {
                result = false;
            }
        }
        catch
        {
            //Any exception will returns false.
            result = false;
        }
    }
    return result;
}
</pre>
<p>Internally WebClient is using the HttpWebRequest and HttpWebResponse classes, so it is good to use the first method.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2009/10/14/how-to-check-remote-file-exists-using-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
