Hi friends, in this article I will explain about how to copy a
text file or notepad file or .txt file.
I already explained in the previous article How to Create, Read, Write, Copy, Move and Delete a Text File or notepad file using C# and VB.NET
"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."
I already explained in the previous article How to Create, Read, Write, Copy, Move and Delete a Text File or notepad file using C# and VB.NET
Copy 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
firstfile As String
= "c:\temp\kishore.txt"
Dim
copyfile As String
= "c:\temp\kishore1.txt"
If
File.Exists(firstfile) Then
' If
file already exists in destination, delete it.
If
File.Exists(copyfile) Then
File.Delete(copyfile)
End
If
File.Copy(firstfile, copyfile)
End If
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)
{
string
firstfile = "c:\\temp\\kishore.txt";
string
copyfile = "c:\\temp\\kishore1.txt";
if
(File.Exists(firstfile)) {
// If
file already exists in destination, delete
it.
if
(File.Exists(copyfile)) {
File.Delete(copyfile);
}
File.Copy(firstfile, copyfile);
}
}
Public
Form2()
{
Load += Form2_Load;
}
}
|
When we execute the above it will copy the firstfile to copy file.If
the firstfile(kishore1.txt) is there in the c:\temp location then it will delete
the file and create a new file kishore1.txt and copy the data from kishore.txt to
kishore1.txt.
"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