Danh mục

C# and .NET FrameworkBài 8: File and RegistryĐoàn Quang Minh minhdqtt@gmail.com

Số trang: 15      Loại file: pdf      Dung lượng: 217.67 KB      Lượt xem: 9      Lượt tải: 0    
tailieu_vip

Hỗ trợ phí lưu trữ khi tải xuống: 1,000 VND Tải xuống file đầy đủ (15 trang) 0
Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

C# and .NET FrameworkBài 8: File and RegistryĐoàn Quang Minh minhdqtt@gmail.com http://www.VTPortal.net Last update: 30. December 2006File and Registry - Editor: Đoàn Quang Editor: Đoà Minh1Mục lụcManaging the File System Moving, Copying, and Deleting Files Reading and Writing to Files The Registry Ứng dụngFile and Registry - Editor: Đoàn Quang Editor: Đoà Minh2Managing the File System.NET hỗ trợ các thao tác làm việc với file– Các tác vụ thông thường như liệt kê file, sao chép, di chuyển, xoá. – Các lớp thao tác với file nằm trong namespace System.IO – Các lớp quan trọng: File, FileInfo, Directory, Path,...Làm việc...
Nội dung trích xuất từ tài liệu:
C# and .NET FrameworkBài 8: File and RegistryĐoàn Quang Minh minhdqtt@gmail.comC# and .NET Framework Bài 8: File and Registry 8: File Đoàn Quang Minh minhdqtt@gmail.com http://www.VTPortal.net Last update: 30. December 2006 Last 30. File and Registry - Editor: Đoàn Quang Editor: oà File 1 Minh Mục lụcManaging the File SystemMoving, Copying, and Deleting FilesReading and Writing to FilesThe RegistryỨng dụng File and Registry - Editor: Đoàn Quang Editor: oà File 2 Minh Managing the File System.NET hỗ trợ các thao tác làm việc với file– Các tác vụ thông thường như liệt kê file, sao chép, di chuyển, xoá.– Các lớp thao tác với file nằm trong namespace System.IO– Các lớp quan trọng: File, FileInfo, Directory, Path,...Làm việc với file và folder– Có 2 loại đối tượng làm việc với file và folder lo Directory và File: chỉ chứa các phương thức tĩnh, không thể khởi Directory File: ch tạo. Thường dùng khi chỉ thực hiện 1 thao tác với 1 file hoặc folder. Khi thao tác, chỉ cần cung cấp đường dẫn đến file hay folder cần làm việc DirectoryInfo và FileInfo: cung cấp các phương thức như 2 đối cung tượng trên, nhưng yêu cầu phải tạo instance. Thường dùng khi thực hiện nhiều thao tác với 1 file hoặc folder. File and Registry - Editor: Đoàn Quang Editor: oà File 3 Minh Managing the File System Tên Ý nghĩaCreationTime Thời gian tạo file hoặc folderDirectoryName (FileInfo), Đường dẫn đầy đủ của folder chứa file hoặc folder hiện thờiParent (DirectoryInfo)Exists File hay folder có tồn tại hay không?Extension Phần mở rộngFullName Tên đầy đủ, cả đường dẫnLastAccessTime Thời gian lần truy cập cuốiLastWriteTime Thời gian lần sửa đổi cuốiName Tên file hay folderRoot Folder gốc (chỉ với DirectoryInfo)Length Dung lượng (bytes), chỉ với FileInfo File and Registry - Editor: Đoàn Quang Editor: oà File 4 Minh Managing the File System// khởi tạo biến myFile trỏ đến một tập tin// khFileInfo myFile = new FileInfo(@C:How to C Sharp.txt); new FileInfo(@C How Sharp.txt// sao chép sang ổ đĩa D// sao sangmyFile.CopyTo(@D:);// kiiểm tra sự tồn tại// kConsole.WriteLine(myFile.Exists.ToString());// ghi thông tin thời điểm tạo file// ghi tin thConsole.WriteLine(myFile.CreationTime.ToString());// cập nhật thời điểm tạo file//myFile.CreationTime = new DateTime(2001, 1, 1, 7, 30, 0); File and Registry - Editor: Đoàn Quang Editor: oà File 5 Minh Managing the File SystemDirectoryInfo theFolder = new DirectoryInfo(folderFullName); new DirectoryInfo(folderFullNameif (!theFolder.Exists) throw new DirectoryNotFoundException(Folder not found: + throw DirectoryNotFoundException(Folder not folderFullName); folderFullNamestring currentPath = theFolder.FullName;string currentPath theFolder.FullName// Lấy tên các thư mục con của thư mục hiện thời//ArrayList folders = new ArrayList(); folders ArrayListforeach(DirectoryInfo folder in theFolder.GetDirectories()) folder theFolder.GetDirectories folders.Add(folder.Name);// Lấy tên các file trong thư mục hiện thời//ArrayList files = new ArrayList(); files ArrayListforeach(FileInfo file in theFolder.GetFiles()) file theFolder.GetFiles files.Add(file.Name); File and Registry - Editor: Đoàn Quang Editor: oà File 6 MinhMoving, Copy ...

Tài liệu được xem nhiều: