Tuesday 19 June 2012

How to Create, Read, Write, Copy, Move and Delete a Text File or notepad file using C# and VB.NET

                                  Hi friends, in this article I will explain about Create, Read, Write, Copy, Move and Delete a Text File or notepad file using C# and VB.NET.
                                 For the Create, Read, Write, Copy, Move and Delete a Text File or notepad file using C# and VB.NET  we have use the namespace System.IO.Because the above file methods included in System.IO namespace.
Create a Text file:
   We can create a text file using the File.CreateText method. The below will create the text file.
VB.NET Code:

Imports System.IO
Imports System.Text
Public Class Form2

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim swriter As StreamWriter
        swriter = File.CreateText("c:\\temp\roja.txt")
        swriter.WriteLine("hi welcome to aspdotnet-roja.blogspot.com")
        swriter.Close()
    End Sub
End Class


C# Code:
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Text;
Public Class Form2
{

     private void Form2_Load(System.Object sender, System.EventArgs e)
     {
          StreamWriter swriter = null;
          swriter = File.CreateText("c:\\temp\roja.txt");
          swriter.WriteLine("hi welcome to aspdotnet-roja.blogspot.com");
          swriter.Close();
     }
    Public Form2()
     {
          Load += Form2_Load;
     }
}

When  we run the above code it will create the roja.txt file.It contains hi welcome to aspdotnet-roja.blogspot.com.

Read the Text File:


             I explained in the further article How to read the text file in C#.NET or VB.NET Windows Forms.


Write to a  Text File:

             I explained in the further article How to write to a Text file or a notepad file or a .txt file or AppendText() mathod in .NET


Copy a  Text File:


             I explained in the further article How to copy a text file or notepad file or .txt file in VB.NET or C# windows forms.



Move a  Text File:


             I explained in the further article How to move the text file or Notepad file or.txt file in VB.NET or C# windows forms



Delete a  Text File:

             I explained in the further article How to delete the text file or Notepad file or.txt file in VB.NET or C# windows forms.

Happy reading my blog.If you like blog then please share it with your friends.


"If you like my blog or articles, you can appreciate by leaving your comments or Liking my Facebook page Aspdotnet-kishore, following on Google+ Aspdotnet-Kishore, Twitter  on AspdotnetKishore, Linked in Aspdotnet-Kishore, stumbling my posts on stumble upon and subscribing on  RSSfeed Aspdotnet-Kishore for free updates directly to your Email inbox . Watch my blog  for more articles"

No comments:

Post a Comment

© 2012-2018 Aspdotnet-Kishore.blogspot.com. All Rights Reserved.
The content is copyrighted to Kishore and may not be reproduced on other websites without permission from the owner.