.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> File Operation >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Merge Files in C#.Net

Posted By:Narayanan       Posted Date: February 23, 2012    Points: 40    Category: File Operation    URL: http://www.dotnetspark.com  

How can i merge a files from one Location to another location? Solution is here.The following two functions are merged a files into one location to another location.

public  void mergefiles(string inputFile, string outputFileName,string filetype)

             #region get PCL file from inputFile
String ftype = “*.” + filetype;
   string[] tmpfiles = Directory.GetFiles(inputFile, ftype);

                #endregion get PCL file from inputFile

                FileStream output = new FileStream(outputFileName, FileMode.Create);

                 #region start Processing

                foreach (string tempInput in tmpfiles)


                   FileStream inputfiles = new FileStream(tempInput, FileMode.Open);

                    CopyStream(output, inputfiles);


                #endregion start Processing



void CopyStream(Stream destination, Stream source)


            int count;

            byte[] buffer = new byte[BUFFER_SIZE];

            while ((count = source.Read(buffer, 0, buffer.Length)) > 0)

                destination.Write(buffer, 0, count);



In First function:
Merge a files in the folder from one location to another location.

For Example:

string inputpath =
string outputpath = @"D:\Test\Test.txt";


Further Readings:

Author: abhays         Company URL: http://www.dotnetspark.com
Posted Date: March 31, 2014

Useful post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend