C#
  Home arrow C# arrow Page 2 - Managing Files in C#
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM Rational Software Development Conference
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C#

Managing Files in C#
By: Barzan "Tony" Antal
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 8
    2008-03-11

    Table of Contents:
  • Managing Files in C#
  • The Foundations
  • Copying, Moving, and Deleting
  • Renaming and File Attributes
  • Final Words

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Managing Files in C# - The Foundations
    (Page 2 of 5 )

    Now that you've started Visual Studio, let's create our new project. It's quite straightforward that we opt for a new C# Windows Application. Once that's created, check out the way I've designed my form. The one and only main form is called frmMain and its sizes are the following: 415, 183. I've disabled the MaximizeBox and set its form border style to FixedSingle.



    I have opted to write the entire code into the frmMain.cs, because this way we eliminate the need to have code snippets in both a separate C# code file and the form with the Windows Form Designer-generated code. All code is within one file in our case, and that's frmMain.cs. Oh, and don't forget to add two dialogs to our form: openFileDialog and saveFileDialog. This is also the way I named them.

    Our project won't require any additional namespaces and/or libraries so we stick to the defaults.


    using System;

    using System.Collections.Generic;

    using System.ComponentModel;

    using System.Data;

    using System.Drawing;

    using System.Text;

    using System.Windows.Forms;


    The name of the project is FileManager, thus the following class is created. By the way, keep in mind that I have intentionally left out the Windows Form Designer-generated code as well as the declarations of components' variables and their configurations. It's your job to configure them. Afterward, the IDE generates the code.


    static class FileManager

    {

    [STAThread]

    static void Main()

    {

    Application.EnableVisualStyles();

    Application.SetCompatibleTextRenderingDefault(false);

    Application.Run(new frmMain());

    }

    }


    As you can see from the above block of code, the application runs the frmMain() public method. It is going to be part of a public partial class. Additionally, as soon as the form is loaded and the components are initialized, we are going to hide the "unnecessary" components from the form and resize only the menu.


    public partial class frmMain : Form

    {

    public frmMain()

    {

    InitializeComponent();

    }

    private void frmMain_Load(object sender, EventArgs e)

    {

    this.txtProperties.Hide();

    this.btnHide.Hide();

    this.lblNewFileName.Hide();

    this.txtNewFileName.Hide();

    this.btnGoRename.Hide();

    this.btnCancel.Hide();

    this.ClientSize = new System.Drawing.Size(145, 158);

    }

    }


    Hide() conceals the control from the user. With the help of ClientSize(), we specify the new size for our frmMain (this refers to that). Now that we have built the basics of our project, we can move on by coding the components and discussing what each of them does. Now comes the real part. Everything that you find below is part of the partial class called frmMain (that's where the Win Form Designer generated code goes also).

    More C# Articles
    More By Barzan "Tony" Antal


       · Thanks for tuning in to read this tutorial. I hope you've found it educational and...
     

    C# ARTICLES

    - Value Types and Reference Types
    - Defining Member and Type Visibility
    - Managing Files in C#
    - Working with Windows Registry in C#
    - Lossless Image Resizing in C#
    - Lossless Image Converting in C#
    - Creating an RSS Feed with ASP.Net Written in...
    - Polymorphism in C#
    - Inheritance in C#
    - C# Events Explained
    - C# Delegates Explained
    - C# StreamReader and StreamWriter Explained
    - C# FileStream Explained
    - A Look at C# File and FileInfo Classes
    - A Look at C# Directory and DirectoryInfo Cla...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway