Thursday, September 29, 2016

Solution for Low Disk Space on C drive

Is your Drive C running out of disk space? If yes, than try to follow the steps mentioned in this video.

I was having "Out of Disk Space" problem with my system as well so I thought to share with others as well. 






Thank You for your valuable time.

Irfan Ahmad alias (Isfan Habib)
(Software Engineer - IV)
LeLafe IT Solutions Pvt. Ltd.
Srinagar, Kashmir 
e-mail: irfanhabib06@gmail.com
cell    : +91-92051 98021

Thursday, February 6, 2014

Fix: Program does not contain a static ‘Main’ method suitable for an entry point

Understanding the problem… Why? When?

When you convert a Winform application into a WPF application –  In a Winform or a Console application, you need a static Main method that acts as an entry point to your executable.  In a WPF application, you do not require any such static class to be present at the compile time.  You need an App.xaml file that appears something like this


1
2
3
4
5
6
7
8
<Application x:Class="MyWPFApplication.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow1.xaml">
<Application.Resources>
</Application.Resources>
</Application>
Here StartupUri represents the first/launch WPF Window or a Page and the App.xaml.cs is very short and simple
1
2
3
4
5
6
7
8
9
10
11
12
using System.Windows;
namespace MyWPFApplication
{
///


/// Interaction logic for App.xaml
///
public partial class App : Application
{
}
}
When you migrate a Winform application to WPF application, you can add this file explicitly to your project to get started. But when you would compile, you will find a compilation issue
Program does not contain a static ‘Main’ method suitable for an entry point
So the compiler treats App.xaml just like any other WPF page instead of a special class which we call it as ApplicationDefinition class.

What is the fix?


Check the properties of App.xaml. Change the Build Action to ApplicationDefinition and re-compile.
This also means, you can have any XAML file to be your ApplicationDefinition file.  But it is preferable to name it App.xaml since it is industry standard and adds consistency to all your projects.

Wednesday, January 29, 2014

SOLUTION - A disk read error occurred. Press Ctrl + Alt + Del to restart

I'm going to share my experience with this dread error message. my nightmare was only short-lived, lasted about 3 hours. But still, hated every moment of it.

I was on my PC working away when suddenly a blue screen came up, the PC restarted and I got the Disk Read Error, press Ctrl Alt Delete to restart.

Then i did and it was stuck in that cycle. i tried booting from the Windows 7 CD and it wouldn't. Then somehow i managed to get the hdd to boot in safe mode. So there i was happily backing everything up. After restarting my PC I couldn't manage to get safe mode again. So back to square one.

I go on my laptop and search google for this error and found this thread on this forum. After reading all of your experiences i found the one most common thing you've all said, about the hardware communication issue. So i thought, i might as well check mine out.

My fix was uber easy.

I opened the back of my PC, I checked the cable going in to my HDD and it felt very firm, didn't feel loose at all. There was lots of dust inside so i cleared that all out. Choaking myself in the process! Then i reattached the cover and rebooted my PC.

It was fixed! That was it, so simple. I believe that there was too much dust clogging up the wrong area of the inside of my PC. So, for anyone with this error, I recommend trying this, check your cables and clean any dust inside before trying more drastic measures such as reformatting or getting new drives etc.

Thanks for everyone's input in this thread, you helped me a great deal. :)

Thursday, September 26, 2013

[SOLVED] "Attaching the Script debugger to process iexplore.exe failed" message after upgrading to Internet Explorer 10

HUGE thanks going out to  Dmitri Leonov - MSFT in a stackoverflow article about the same message.
After updating to Internet Explorer 10, I started receiving the error when debugging with Visual Studio 2010:

"Attaching the Script debugger to process [####] iexplore.exe failed.  Another debugger may already be attached to the process."

The fix:

  • Close all instances of Internet Explorer.  (I will add you can leave Visual Studio open)
  • Run a command prompt as Administrator and paste this little gem into the command line:

It worked like a champ for me (and apparently others from comments on the stackoverflow post.)

Good riddance to an annoying message!  Happy coding.

Sunday, September 1, 2013

Create a TreeView with Category and CategoryParent from a Database in Windows Forms and C#

Introduction

A TreeView control provides a way to display information in a hierarchical structure using nodes. 

Root Node (Parent Node)

The top level nodes in a TreeView is called the Root nodes.

Child nodes

The root nodes (also known as parent nodes) can have nodes that can be viewed when they are expanded. These nodes are called child nodes. The user can expand a root node by clicking the plus sign (+) button.

Table Definitions

Parent Nodes
CREATE TABLE [dbo].[MNUPARENT](
               [MAINMNU] [varchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
               [STATUS] [varchar](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
               [MENUPARVAL] [int] IDENTITY(1,1) NOT NULL,
 CONSTRAINT [PK_MNUPARENT] PRIMARY KEY CLUSTERED
(
               [MENUPARVAL] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
Insert Sample Hierarchical Data
 
SET IDENTITY_INSERT MNUPARENT ON
GO

INSERT INTO MNUPARENT(MAINMNU, STATUS, MENUPARVAL) VALUES('Finanace','Y',1)
INSERT INTO MNUPARENT(MAINMNU, STATUS, MENUPARVAL) VALUES('Inventory','Y',2)

GO
SET IDENTITY_INSERT MNUPARENT OFF
GO

Child Nodes
 
CREATE TABLE [dbo].[MNUSUBMENU](
               [MENUPARVAL] [int] NOT NULL,
               [FRM_CODE] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
               [FRM_NAME] [varchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
               [MNUSUBMENU] [int] NOT NULL,
               [STATUS] [varchar](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
PRIMARY KEY CLUSTERED
(
               [MNUSUBMENU] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
N [PRIMARY]

Sample Insert Statements
 
INSERT INTO MNUSUBMENU(MENUPARVAL,FRM_NAME,MNUSUBMENU,STATUS) VALUES(1,'Child Finance',10,'Y')
INSERT INTO MNUSUBMENU(MENUPARVAL,FRM_NAME,MNUSUBMENU,STATUS) VALUES(1,'Accounting',20,'Y')
INSERT INTO MNUSUBMENU(MENUPARVAL,FRM_NAME,MNUSUBMENU,STATUS) VALUES(20,'Audit',30,'Y')
INSERT INTO MNUSUBMENU(MENUPARVAL,FRM_NAME,MNUSUBMENU,STATUS) VALUES(30,'Acc. Standards',40,'Y')

Alternatively, you can have a single table to maintain this data of parent and child nodes.

Now let us start a new project and populate the TreeView.
  1. Create a new project and name it LoadTreeView.

    Image1.jpg
     
  2. Set the form's Name Property to FrmTreeView and its Text Property to Populate TreeView.
  3. Add a tree view control to the form and set its dock property to Left
  4. To configure the connection settings of the Data Source add an application configuration File

    From Project -> "Add" -> "New Item..."

    Image2.jpg
     
  5. Paste the code below into the App.config File:
    xml version="1.0" encoding="utf-8" ?><configuration>
      <
    connectionStrings>
        <
    add name ="ConnString" connectionString ="Data Source=yourServerName; User Id =yourUserName; Password =yourPwd;" providerName ="System.Data.SqlClient"/>  </connectionStrings></configuration>

  6. To access the connection string from code add a reference to System.Configuration and add the namespace using System.Configuration.

    Image3.jpg
     
  7. In the form's Load Event paste the following code:
     
    String connectionString;
    connectionString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
    conn = new SqlConnection(connectionString);
    String Sequel = "SELECT MAINMNU,MENUPARVAL,STATUS FROM MNUPARENT";
    SqlDataAdapter da = new SqlDataAdapter(Sequel, conn);
    DataTable dt = new DataTable();
    conn.Open();
    da.Fill(dt);

    foreach (DataRow dr in dt.Rows)
    {
        parentNode = treeView1.Nodes.Add(dr["MAINMNU"].ToString());
        PopulateTreeView(Convert.ToInt32(dr["MENUPARVAL"].ToString()), parentNode);
    }treeView1.ExpandAll();
  8. The Treeview is populated with its child nodes using the PopulateTreeView Method we have defined as in the following:
     
    private void PopulateTreeView(int parentId, TreeNode parentNode)
    {
        String Seqchildc = "SELECT MENUPARVAL,FRM_NAME,MNUSUBMENU FROM MNUSUBMENU WHERE MENUPARVAL=" + parentId + "";
        SqlDataAdapter dachildmnuc = new SqlDataAdapter(Seqchildc, conn);
        DataTable dtchildc = new DataTable();
        dachildmnuc.Fill(dtchildc);
        TreeNode childNode;
        foreach (DataRow dr in dtchildc.Rows)
        {
            if (parentNode == null)
                childNode = treeView1.Nodes.Add(dr["FRM_NAME"].ToString());
            else
                childNode = parentNode.Nodes.Add(dr["FRM_NAME"].ToString()); 
                PopulateTreeView(Convert.ToInt32(dr["MNUSUBMENU"].ToString()), childNode);
        }}
  9. Build and run the program that results in the output shown in the following:

    Image4.jpg
     
  10. Add the following piece of code to the treeview Double-Click Event:
     
    private void treeView1_DoubleClick(object sender, EventArgs e)
    {
        MessageBox.Show(treeView1.SelectedNode.FullPath.ToString());}
  11. When you double-click a node on the Treeview control a message is displayed with the fullpath to the node. Here I have clicked the Acc. Standards node.

    Image5.jpg

    Program
     
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Configuration;
    using System.Data.SqlClient;

    namespace LoadTreeView
    {
        public partial class FrmTreeView : Form
        {
            SqlConnection conn;
            TreeNode parentNode = null;
            public FrmTreeView()
            {
                InitializeComponent();
            }

            private void FrmTreeView_Load(object sender, EventArgs e)
            {
                String connectionString;
                connectionString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
                conn = new SqlConnection(connectionString);
                String Sequel = "SELECT MAINMNU,MENUPARVAL,STATUS FROM MNUPARENT";
                SqlDataAdapter da = new SqlDataAdapter(Sequel, conn);
                DataTable dt = new DataTable();
                conn.Open();
                da.Fill(dt);

                foreach (DataRow dr in dt.Rows)
                {
                    parentNode = treeView1.Nodes.Add(dr["MAINMNU"].ToString());
                    PopulateTreeView(Convert.ToInt32(dr["MENUPARVAL"].ToString()), parentNode);
                }

                treeView1.ExpandAll();
            }

            private void PopulateTreeView(int parentId, TreeNode parentNode)
            {
                String Seqchildc = "SELECT MENUPARVAL,FRM_NAME,MNUSUBMENU FROM MNUSUBMENU WHERE MENUPARVAL=" + parentId + "";
                SqlDataAdapter dachildmnuc = new SqlDataAdapter(Seqchildc, conn);
                DataTable dtchildc = new DataTable();
                dachildmnuc.Fill(dtchildc);
                TreeNode childNode;
                foreach (DataRow dr in dtchildc.Rows)
                {
                    if (parentNode == null)
                        childNode = treeView1.Nodes.Add(dr["FRM_NAME"].ToString());
                    else
                        childNode = parentNode.Nodes.Add(dr["FRM_NAME"].ToString());

                    PopulateTreeView(Convert.ToInt32(dr["MNUSUBMENU"].ToString()), childNode);
                }
            }

            private void treeView1_DoubleClick(object sender, EventArgs e)
            {
                MessageBox.Show(treeView1.SelectedNode.FullPath.ToString());
            }

        }
    }
Conclusion

In this article we have discussed how to populate a treeview dynamically in a C# application and display the entire path to the node on an event.