C#
  Home arrow C# arrow Page 2 - Managing Files in C#
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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 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
     
     
    ADVERTISEMENT


    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...
       · Please provide Programme output.
     

    C# ARTICLES

    - Coding a CRC-Generating Algorithm in C
    - Cyclic Redundancy Check
    - Handling Methods and Functions
    - Destroying Objects in C#
    - Creating Objects in C-Sharp
    - Classes and Objects
    - Programming Languages: Managed versus Native
    - LINQ-to-MySQL with DbLinq in C#
    - Working with Dates and Times in C#
    - Generics, Dictionaries, and More
    - More About Generics
    - Working with C# Collections
    - Generics
    - C# and XML
    - Pointers and Arrays in C#





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek