Chapter 6: Creating Windows–based Applications 1 Microsoft® Visual C# 2008.

Slides:



Advertisements
Similar presentations
Files & Streams. Files Introduction Files are used for long-term retention of large amounts of data, even after the program that created the data terminates.
Advertisements

Introduction to the C# Programming Language for the VB Programmer.
File Systems Files and directories Absolute and relative names Text and binary files Sequential-access and random-access files.
ASP.NET Programming with C# and SQL Server First Edition
Chapter 6: Using VB.NET Supplied Classes Visual Basic.NET Programming: From Problem Analysis to Program Design.
C# Programming: From Problem Analysis to Program Design1 Working with Files C# Programming: From Problem Analysis to Program Design 3 rd Edition 13.
File and Streams There are many ways of organizing records in a file. There are many ways of organizing records in a file. The most common type of organization.
MIS316 – BUSINESS APPLICATION DEVELOPMENT – Chapter 14 – Files and Streams 1Microsoft Visual C# 2012, Fifth Edition.
Understanding Input/Output (I/O) Classes Lesson 5.
Computer and Programming File I/O File Input/Output Author: Chaiporn Jaikaeo, Jittat Fakcharoenphol Edited by Supaporn Erjongmanee Lecture 13.
Lecture Set 12 Sequential Files and Structures Part B – Reading and Writing Sequential Files.
Stream Handling Streams - means flow of data to and from program variables. - We declare the variables in our C++ for holding data temporarily in the memory.
Chapter 12 Working with Files CIS 3260 Introduction to Programming using C# Hiro Takeda.
Neal Stublen Open/Close Connections  ADO.NET uses “connection pooling” to optimize opening and closing connections to the database.
Microsoft Visual Basic 2008 CHAPTER NINE Using Arrays and File Handling.
Microsoft Visual Basic 2005 CHAPTER 9 Using Arrays and File Handling.
Assemblies & Namespaces1. 2 Assemblies (1).NET applications are represented by an assembly An assembly is a collection of all software of which the application.
Using Arrays and File Handling
Lector: Aliyev H.U. Lecture №5 Telecommunication network software design with.NET. Using streams for network programming TASHKENT UNIVERSITY OF INFORMATION.
How to Work with Numeric and String Data
Methods Session 04 Mata kuliah: M0874 – Programming II Tahun: 2010.
Streams & File Input/Output Basics C#.Net Development Version 1.1.
File I/O Static void Main( ) {... } data. Topics I/O Streams Reading and Writing Text Files Formatting Text Files Handling Stream Errors File Pointers.
Files and Streams File Types, Using Streams, Manipulating Files SoftUni Team Technical Trainers Software University
Reference: Lecturer Lecturer Reham O. Al-Abdul Jabba lectures for cap211 Files and Streams- I.
1 COMP3100e Developing Microsoft.Net Applications for Windows (Visual Basic.Net) Class 6 COMP3100E.
File I/O What We’ll Cover –Visual Basic Techniques for Text Files –.NET Techniques for Text Files What We’ll Not Cover –Binary File I/O –XML File I/O.
Object Oriented Software Development 10. Persistent Storage.
Chapter 2 Part C – More on the Help System and The Object Browser (scan quickly for future reference)
File Input and Output (I/O) Engineering 1D04, Teaching Session 7.
Files and Streams. Objectives Learn about the classes that support file input/output Understand the concept of abstraction and how it related to the file.
CS360 Windows Programming
Chapter 14: Files and Streams. 2Microsoft Visual C# 2012, Fifth Edition Files and the File and Directory Classes Temporary storage – Usually called computer.
BIM313 – Advanced Programming File Operations 1. Contents Structure of a File Reading/Writing Texts from/to Files File and Directory Operations 2.
Chapter 8 Files 1/4/20161Copyright © 2012 Thomas P. Skinner.
Text Files and String Processing
Input and Output 23: Input and Output
CSC 298 Streams and files.
Object-Oriented Application Development Using VB.NET 1 Chapter 4 VB.NET Programming with Supplied Classes.
Ajay Tripathi Input Output. Ajay Tripathi Input/output (IO) refers to the operations for reading and writing data to streams and files. In the.NET Framework,
Files and Streams. What is a file? Up until now, any stored data within a program is lost when the program closes. A file is a permanent way to store.
Chapter 6: Using VB.NET Supplied Classes Visual Basic.NET Programming: From Problem Analysis to Program Design.
Strings in C++/CLI us/library/system.string.aspxhttp://msdn.microsoft.com/en- us/library/system.string.aspx public: static.
Files and Streams. Objectives Learn about the classes that support file input/output Understand the concept of abstraction and how it related to the file.
1 Statements © University of Linz, Institute for System Software, 2004 published under the Microsoft Curriculum License.
VB.Net. Topics Introduction to VB.Net Creating VB.Net Project in VS 2005 Data types and Operators in VB.Net String Functions Conditions (If Else, Select.
Files and Streams Lec Introduction  Files are used for long-term retention of large amounts of data, even after the program that created the.
INF230 Basics in C# Programming
Module 6: Building .NET–based Applications with C#
Input and Output 23: Input and Output
C# Programming: From Problem Analysis to Program Design
© 2016, Mike Murach & Associates, Inc.
Defiana Arnaldy, M.Si File and Stream I/O Defiana Arnaldy, M.Si
File Types, Using Streams, Manipulating Files
How to work with files and data streams
Files and Streams.
C# Programming: From Problem Analysis to Program Design
Chapter 3 The .NET Framework Class Library (FCL)
Files and Streams Lect3 CT1411.
Sequential Input and Output using Text Files
File Input/Output (I/O)
טיפול בקבצים ליווי מקצועי : ארז קלר
Files & Streams.
Files and Streams Lect10 GC201 12/1/2015.
Lecture 16 File I/O Richard Gesick.
How to work with files and data streams
Introduction to Programming Lecture 6
Files and Streams.
.Net Framework: A Survey of Important Libraries
Jim Fawcett CSE775 – Distributed Objects Spring 2012
Presentation transcript:

Chapter 6: Creating Windows–based Applications 1 Microsoft® Visual C# 2008

Overview Examining the.NET Framework Class Library Formatting Strings and Numbers Using Streams and Files 2

Lesson: Examining the.NET Framework Class Library 3.NET Framework Class Library The Object Browser

.NET Framework Class Library Classes in the.NET Framework class library are arranged into a hierarchy of namespaces Most common namespaces System System.Data System.Drawing System.Windows.Forms System. Web.Services System. Web.UI System.Collections System.Diagnostics System.IO

The Object Browser Allows you to examine and discover objects and their members

6 Practice: Using the Object Browser In this practice, you will open Object Browser, navigate namespaces and members, and document your results Hands-on Practice

Lesson: Formatting Strings and Numbers 7 How to Format Numbers How to Format Date and Time How to Create Dynamic Strings

How to Format Numbers 8 Some.NET Framework classes use format strings to return common numeric string types, including these methods: o String.Format, ToString, Console.WriteLine String.Format class example o The {0:c} is the formatting information, where "0" is the index of the following objects ":c" dictates that the output use the currency format o Output is $12, (on a US English computer) Custom numeric format strings apply to any format string that does not fit the definition of a standard numeric format string o # character in the number example string s = String.Format( "{0:c}", );

How to Format Date and Time 9 System.DateTime dt = new System.DateTime(2002,3,20,10,30,0); MessageBox.Show(dt.ToString("f")); System.DateTime dt = new System.DateTime(2002,3,20,10,30,0); MessageBox.Show(dt.ToString("f")); DateTimeFormatInfo class o Used for formatting DateTime objects o String output is: Wednesday, March 20, :30 AM Custom formatting string o String output is: 20 Mar :30:00 System.DateTime dt = new System.DateTime(2002,3,20,10,30,0); MessageBox.Show(dt.ToString("dd MMM yyyy - hh:mm:ss")); System.DateTime dt = new System.DateTime(2002,3,20,10,30,0); MessageBox.Show(dt.ToString("dd MMM yyyy - hh:mm:ss"));

How to Create Dynamic Strings 10 for (int i=0; i < 1000; i++) { s = s.Concat(s, i.ToString()); } for (int i=0; i < 1000; i++) { s = s.Concat(s, i.ToString()); } Question: After executing the following code, how can you preserve computer memory? StringBuilder s = new StringBuilder(); for (int i=0; i < 1000; i++) { s.Append(i); } StringBuilder s = new StringBuilder(); for (int i=0; i < 1000; i++) { s.Append(i); } Solution: Use the StringBuilder Class

11 Practice: Formatting Strings In this practice, you will provide the correct formatting code that produces the required output to a series of formatting questions provided in a C# application Hands-on Practice

Lesson: Using Streams and Files 12 What Is File I/O? How to Read and Write Text Files How to Read and Write Binary Files How to Traverse the Windows File System

What Is File I/O? 13 A file is a collection of data stored on a disk with a name and often a directory path A stream is something on which you can perform read and write operations FileAccess Enumerations o Read, ReadWrite, Write FileShare Enumerations o Inheritable, None, Read, ReadWrite, Write FileMode Enumerations o Append, Create, CreateNew, Open, OpenOrCreate, Truncate

How to Read and Write Text Files 14 ClassExample StreamReader StreamReader sr = new textBox1.Text = sr.ReadToEnd(); sr.Close(); StreamWriter StreamWriter sw = new sw.WriteLine("Log Line 1"); sw.WriteLine("Log Line 2"); sr.Close(); XmlTextReader public class XmlTextReader : XmlReader, IXmlLineInfo XmlTextWriter w.WriteStartElement("root"); w.WriteAttributeString("xmlns", "x", null, "urn:1"); w.WriteStartElement("item","urn:1"); w.WriteEndElement(); w.WriteEndElement();

How to Read and Write Binary Files 15 BinaryReader o Reads primitive data types as binary values in a specific encoding BinaryWriter o Writes primitive types in binary to a stream and supports writing strings in a specific encoding FileStream fs = new BinaryWriter w = new BinaryWriter(fs); w.Write((byte)65); w.Write((byte)66); w.Close(); fs.Close(); FileStream fs = new BinaryWriter w = new BinaryWriter(fs); w.Write((byte)65); w.Write((byte)66); w.Close(); fs.Close();

How to Traverse the Windows File System 16 Using the DirectoryInfo and FileInfo classes DirectoryInfo d = new DirectoryInfo("C:\\"); DirectoryInfo[] subd = d.GetDirectories(); foreach (DirectoryInfo dd in subd) { if (dd.Attributes==FileAttributes.Directory) { FileInfo[] f = dd.GetFiles(); foreach (FileInfo fi in f) { listBox1.Items.Add(fi.ToString()); } DirectoryInfo d = new DirectoryInfo("C:\\"); DirectoryInfo[] subd = d.GetDirectories(); foreach (DirectoryInfo dd in subd) { if (dd.Attributes==FileAttributes.Directory) { FileInfo[] f = dd.GetFiles(); foreach (FileInfo fi in f) { listBox1.Items.Add(fi.ToString()); } Using recursion o Technique where a function calls itself, repeatedly, passing in a different parameter

17 Practice: Using File System Information In this practice, you will create a Windows-based application that calculates the size of all the files that are contained in a folder Hands-on Practice

Review 18 Examining the.NET Framework Class Library Overriding Methods from System.Object Formatting Strings and Numbers Using Streams and Files

19 Lab 6.1: Using Streams Exercise 1: Converting a Binary File to a Text File