Wrox Programmer Forums
|
BOOK: Professional C# 2008 ISBN: 978-0-470-19137-8
This is the forum to discuss the Wrox book Professional C# 2008 by Christian Nagel, Bill Evjen, Jay Glynn, Morgan Skinner, Karli Watson; ISBN: 9780470191378
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional C# 2008 ISBN: 978-0-470-19137-8 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 4th, 2009, 03:20 AM
Registered User
 
Join Date: Oct 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to sossoumarcel
Red face C# API To scan system Directory

Hello,

I am working on an application that needs to access a local directory scan it and display the content RootDirectory>SubDirectory type of listing.

I have been trying different codes but not getting any output.
I don't know if i am using the appropriate language or the wrong approach!


Take a look at this code:

Code:
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

       


        public class DirectoryObject
        {
            static void Main(string[] args)
            {

                DirectoryInfo MyRoot = new DirectoryInfo(@"C:\Documents and Settings\My Documents");
                DirectoryInfo[] MySub;
                DirectoryInfo TheFolder = null;
                FileInfo[] MyFiles;
                FileInfo TheFile = null;
                FileStream MyStream;
                MyRoot.CreateSubdirectory("MyFolder");
                MySub = MyRoot.GetDirectories();
                foreach (DirectoryInfo D in MySub)
                {

                    if (D.Name == "MyFolder")
                        TheFolder = D;

                }

                MyFiles = TheFolder.GetFiles();
                foreach (FileInfo F in MyFiles)
                {

                    if (F.Name == "Testing.txt")
                    {

                        TheFile = F;
                        MyStream =
                        TheFile.Open(FileMode.Create,
                         FileAccess.ReadWrite,
                        FileShare.ReadWrite);

                        int i = 0;
                        byte b = 0;

                        while (i != 000)
                        {
                            MyStream.WriteByte(b); i++; b++;
                        }
                    }
                }

               //TheFile.Delete();
               //TheFolder.Delete();
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            FileInfo test = new FileInfo(@ "C:\Documents and Settings\My Documents");
            Console.WriteLine(test.Exists.ToString());
        }

       

    }
}
namespace WindowsFormsApplication1
{
	public class Test

	{
		public static void Main(string [] args)
        {
            FileSystemWatcher watcher = new FileSystemWatcher();
            watcher.Path = @"C:\Documents and Settings\s_sossou\My Documents";
            watcher.NotifyFilter = 
                                    NotifyFilters.LastAccess|               
                                    NotifyFilters.LastWrite|
                                    NotifyFilters.FileName|
                                    NotifyFilters.DirectoryName;
            watcher.Filter = "*.txt";
            watcher.Changed += new FileSystemEventHandler(Onchanged);
            watcher.Created += new FileSystemEventHandler(Onchanged);
            watcher.Deleted += new FileSystemEventHandler(Onchanged);
            watcher.Renamed += new RenamedEventHandler(OnRenamed);
            watcher.EnableRaisingEvents = true;
        }
        public static void Onchanged(object source,
                                     FileSystemEventArgs e)
        {
            Console.WriteLine("Event Fired");
        }


        public static void  OnRenamed(object source, RenamedEventArgs e)
{
 	Console.WriteLine("Event Fired");
}
    }
}
public class Test
{
    private void folderBrowserDialog1_HelpRequest(object sender, EventArgs e)
    {
        Console.WriteLine("Event Fired");
    }

}

Thanks in advance,
 
Old December 13th, 2009, 12:34 AM
Friend of Wrox
 
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default

goto my weblog http://irproject.6te.net and click the link posited in the center of screen
note that comments are written in Persian but codes are self-describing





Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto Scan aidah_abdul79 VB.NET 2002/2003 Basics 0 June 7th, 2006 08:36 PM
Directory Management System aarunlal ASP.NET 2.0 Professional 1 March 3rd, 2006 03:55 PM
Active Directory and Windows System Files frleonard ASP.NET 1.x and 2.0 Application Design 0 February 25th, 2006 08:41 PM
RegOpenKey api always get System.NotSupportedExcep kitsam General .NET 0 January 9th, 2005 10:25 PM
Virus Scan koneruvijay VS.NET 2002/2003 0 February 24th, 2004 03:35 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.