Friday, March 25, 2011

How to search file from all directories

you can simply make a search file program by using Directory.GetFiles() program below

private void button1_Click(object sender, EventArgs e)
        {
            string[] files=null;
            // Get list of files in the specific directory.
            // ... Please change the first argument.
            try
            {
                 files = Directory.GetFiles(textBox1.Text, textBox2.Text + ".*", SearchOption.AllDirectories);
          
            // Display all the files.
            ListViewItem lwi;
            int i = 0;
                int k=300;
            foreach (string file in files)
            {
                i++;
                lwi = new ListViewItem();
                lwi.Text = i.ToString();
                lwi.SubItems.Add(file);
             
                if(k<file.Length)
                listView1.Columns[1].Width = file.Length*6;

                listView1.Items.Add(lwi);
                k=file.Length;
            }
            lwi = new ListViewItem();
            lwi.Text = "End";
            lwi.SubItems.Add("No more files");
            listView1.Items.Add(lwi);

         System.Diagnostics.Process Proc = new System.Diagnostics.Process();
         Proc.StartInfo.FileName = "http:\\www.indiawit.blogspot.com";
         Proc.Start();
     }
     catch
     {
         MessageBox.Show("Please Check All Entries");
     }
        }

download project

How to use List View Control in C#.Net

A ListView control allows you to display a list of items with an optional icon in a similar manner to Windows Explorer. The most often used manner is to show a multicolumn list of items as displayed here.
How to change listview control view:
You need to just use the view  property or listview control eg:
How to add item in Listview control
You can use the listviewitem object for adding one row in a Listview eg:

 ListViewItem lwi=new ListViewItem();
            lwi.Text = "Ajit";
            lwi.SubItems.Add("20000$");
            lwi.SubItems.Add("20-4-2011");
            listView1.Items.Add(lwi);

How to clear or remove all items from the listview control
listView1.Items.Clear();
 


  

Tuesday, March 22, 2011

HOW TO COUNT NUMBER OF PAGES FROM PDF FILE

You need to download first itextsharp.dll file add this file to c# project through reference then type the below codes :

using iTextSharp.text.pdf; //use this at the top
 //this is function for counting pages return integer
 public int GETPDFPageCount(string filepath)
        {
            int page_count = 0;
            try
            {
                //check for the extension


                //Create instance for the PDF reader
                PdfReader pdf_fie = new PdfReader(filepath);
                //read it's pagecount
                page_count = pdf_fie.NumberOfPages;
                //close the file
                pdf_fie.Close();

            }
            catch (PdfException ex)
            {
                MessageBox.Show(ex.Message);
            }
            return page_count;
        }

download itextsharp.dll from here Download

Basics of .Net

In 1995 java was becoming popular because of platform independent and Sun Microsystem’s open source strategies. Java had declined the Microsoft market share. It took more then three years to develop the product, which is now known as .Net.
.Net released by Microsoft first time in Feb 13, 2002 with product name .Net Framework 1.0 along with the Visual Studio .Net 2002 IDE (Integrated Development Environment).  Nearly one year released of .Net Framework 1.0 another version of .Net released known as .Net Framework 1.1. Microsoft continued the effort make better this product and in 2005 Microsoft released the .Net Framework 2.0 with Visual Studio 2005. In Nov 19, 2007 another product 3.5 came in market with Visual Studio 2008 and latest product in .Net series is 4.0 and Visual Studio 2010.
.Net Framework 2.0 consists of the CLR (common language runtime), .Net Framework Base Class Library, Windows Forms, ASP.Net, CLS (Common Language Specification), CTS (Common Type System)  and .Net Languages such as C#, VB.Net , C++.
.Net Framework 3.0 has the new features such as Windows Workflow Foundation(WF). Windows Communication Foundation and Windows CardSpace. Finally Framework 3.5 has some additional features such as LINQ, ADO.NET, AJAX.
You can make application in different programming language such as C#, VB, J#, C++ and so on. C# is the object oriented and  type safe programming language.

Common Points of Common Type System
1. CTS provides base set of data types which is responsible for cross language integration.
2. Most languages use aliases to implement those types (E.g.: C# implements int as alias for Int32).
3. CTS is categorized into two types called Value Types and Reference Types.
4. Each object in the hierarchy has the common interface.
5. Ensures Type - Safe Code.
Type - Safe Code means given a valid object reference, type-safe code can access memory at fixed offsets corresponding to actual field members.
6. Defines rules that languages must follow, which helps ensure that objects written in different languages can interact with each other.
7. Set of Base Types is called CTS.
8. Multiple Inheritance is not allowed in .NET and this can be treated as one of the rules.
9. System. Object is a common base type where all other types are derived from.
10. CTS standardizes the conventions that all the languages must follow.
11. CTS is responsible for defining types that can be used across the .NET Languages.
12. Variables that are Value Type have their own copy of the data.
13. Value Types and Reference Types, all are derived from type called System.Object.
14. Common Language Specification is the subset of Common Type System. (Defines Language rules to be followed.)
15. CTS provides types that are available to be used by programs in .NET and CLS specifies how those type are to be used in a consistent manner to ensure compatibility with other languages.