.NET
Oct 1

C# Scanning a HardDrive

            

c# scan files            

            

Introduction

            

Here is how to use C# to scan through files in the computer and add  them to a TreeView control. There are two main functions to accomplish the task. One for scanning directions. The other for creating nodes and child nodes in the TreeView. Both are easily done with recursive C# functions...

            

  

          

To review, a recursive function is one that calls itself. When scanning directories for a list of files, recursion is useful so the function can scan all files and subdirectories. Subdirectories might have more subdirectories etc.

            

To add the files to the TreeView, we want to be able to  supply a path string such as “C:\Folder1\Folder2\file1.txt” and have the  TreeView create nodes and children nodes to match the path. Recursion is then  an easy way to add a path to a TreeView control.

          

Scanning Directories

            

To scan directories the C# function first needs the root  directory. The C# Directory class the two functions we need:  GetDirectories and GetFiles.

            
Directory.GetDirectories(“C:\\”) //returns an array of paths
Directory.GetFiles(“C:\\”) //returns an array of file paths
                      

The recursive call comes in when the C# function calls itself  for each directory in the GetDirectories list.

            
scanFiles(directories[i]); //For Example
Sep 11
     

Trong phần này, chúng ta sẽ xem xét hỗ trợ cho XPath và XSL Transforms (XSLT) trong .NET Framework. XPath được hỗ trợ thông qua không gian tên System.Xml.XPath, và XSLT được hỗ trợ thông qua không gian tên System.Xml.Xsl. Lí do xem xét cả hai lớp trên là vì lớp XPathNavigator của không gian tên System.XPath cung cấp cách rất thực tế để thực thi các biến đổi XSL trong .NET.  

XPath là một ngôn ngữ truy vấn cho XML. Bạn sẽ dùng XPath để chọn một bộ con các các yếu tố giá trị văn bản hoặc các giá trị thuộc tính. XSLT được dụng để thay đổi một tài liệu gốc sang một tài liệu với một cấu trúc kiểu khác.

Trước tiên chúng ta sẽ xem xét System.XPath và trình bày cách dùng các lớp System.Xml.Xsl.

Không gian tên System.XPath

Không gian tên System.XPath được xây dựng dựa trên yếu tố tốc độ. Nó cung cấp một thể hiện chỉ đọc cho tài liệu XML của bạn, vì vậy không có vấn đề soạn thảo ở đây. Các lớp trong không gian này được xây dựng đẻ thực thi lặp nhanh và lựa chon trên tài liệu XML trong một con trỏ.

Đây là một bảng liệt kê các lớp trong System.XPath, và một giải thích ngắn vì hỗ trợ của mỗi lớp:  

                                                                                                                                                                 
        

Class Name

      
        

Description

      
        

XPathDocument          

      
        

Một view của tài liệu XML . Chỉ đọc.

      
        

XPathNavigator          

      
        

Cung cấp khả năng điều hướng cho một         XPathDocument.

      
        

XPathNodeIterator          

      
        

Cung cấp khả năng truy xuất trực tiếp các         nút. XPath trang bị một bộ nút trong Xpath.

      
        

XPathExpression          

      
        

Một biên dịch phương thức XPath. Được dùng         bởi SelectNodes, SelectSingleNodes, Evaluate, và         Matches.

      
        

XPathException          

      
        

XPath exception class.

      

XPathDocument


Aug 18
Sau khi bấm "GetItNow", chương trình sẽ lấy những file đang được tạo trong folder "D:\Games" & copy chúng sang "D:\UpdatedGames".

Bây giờ muốn cập nhật cho máy khác thì chỉ cần copy từ D:\UpdatedGames thôi để giảm lượng file không cần copy lại.

Mọi người xài thử xem có ổn định không. Có gì góp ý cho mình bổ sung những gì thiếu xót nhé. Thanks!

Bấm xem ảnh ở cửa sổ mới

Tệp tin tải về

Aug 12

File monitoring using FileSystemWatcher

Download this Visual Studio 2005 project Download this project (C# 2005)
    
     Wondering what's cranking your harddisk so hard? Using C# (.NET 1.1 or 2.0, whichever you prefer) and the FileSystemWatcher object you can easily build yourself a file monitoring application. You'll be able to see what files are being created, changed, renamed or deleted.
     First we're going to write a few lines of code to quickly see how the FileSystemWatcher object operates. Then after we get the hang of it, we'll be building a simple Windows application that monitors a folder (or drive) for changes and writes the events to a log.
Aug 12
Bước 1: Bạn tạo 1 project mới trong vb. Sau đó vào menu Project -> Refference. Tìm: Microsoft WMI Scripting Vx.x Library (trong đó Vx.x là phiên bản của thư viện WMI).

Bước 2: Dán đoạn code sau vào form
Lưu ý:
- Chương trình theo dõi sự thay đổi ở nhánh registry: HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run.  Bạn có thể sửa lại theo ý.

- Chương trình sẽ thông báo bằng cách in ra màn hình watch của IDE, bạn có thể sửa lại theo ý mình.
Phân trang 1/2 Trang đầu 1 2 Trang sau Trang cuối [ Kiểu hiển thị Trích dẫn | Liệt kê ]