Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,
How can i merge files into One file.files contain texts/lines/Images .So how can i merge the files. Please Help me. It is an Windows Application.
Posted

1 solution

It really depends on what you want to do with them, how many you have, and so forth.
If you really want to combine any number of any files into a single file, then you probably should look at ZIPing them.
There is an article here which may help: C# Zip Files and/or Folders[^]
 
Share this answer
 
Comments
naraayanan 23-Feb-12 6:07am    
Thanks for reply. I applied the following code.but It does not work .why?Please tell me.
#region Merged Multiple Files
public static void mergefiles(string inputpath,string outputPath)
{
try
{
string[] tmpfiles = Directory.GetFiles(inputpath, "*.pcl");
using (StreamWriter writer = File.CreateText(outputPath))
{
foreach (string tempFile in tmpfiles)
{
using (StreamReader reader = File.OpenText(tempFile))
{
writer.Write(reader.ReadToEnd());
}
}
}
}
catch (Exception ex)
{
Program.WriteLog(ex.Message, ex.StackTrace);
}


}

#endregion Merged Multiple Files
OriginalGriff 23-Feb-12 8:48am    
It will work - but it won't do what you want it to.
While it will happily write all the files into one big file, it won't let you read them back again, because it doesn't include any code or markers, or directory to say where one ends and the next starts.
You need to either include that info, and the type of the file, and probably the file name, or use something that does include it. Like ZIP for example. :laugh:
Paul E Davies 23-Feb-12 8:20am    
Although I can see potential issues with your code it would be useful if you could expand on the reasons why it doesn't work.

Are you recieving errors, if so when (compilation errors, runtime errors) and what are those errors.

If no errors in what way is the output wrong? No output? output in unexpected format?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900