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


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

Merge files in C#.net

Posted By: Narayanan     Posted Date: February 23, 2012    Points:5   Category :C#
Hi friends,
How can i merge a files into one file? files contain text or image or line.So How can i merge the files in c#.net please help me.it is an Windows Application.

Responses
Author: Mahesh             
Posted Date: March 01, 2012     Points: 20   

Hi following code will merge Text files,

Public Function text_combine( ByVal path_to_read_file As String, ByVal path_to_append_file As String ) As Boolean
If ((IO.File.Exists(path_to_read_file)) And (IO.File.Exists(path_to_append_file)) ) Then
Try
System.IO.File.AppendAllText( path_to_append_file, System.IO.File.ReadAllText(path_to_read_file) )
text_combine = True
Catch ex As Exception
text_combine = False
End Try
Else
text_combine = False
End If
End Function

and for merging PDF files follow link below,
http://www.vbforums.com/showthread.php?t=462929

Hope this help....

Regards
Mahesh

Author: Narayanan             
Posted Date: March 01, 2012     Points: 20   

Hi,
I think, This is One File to another File.But i want to merge all files.
For Ex:
I have a two folders
1)Input
2)Output

in that Input Folder ,it contains a 4/5 text files.SO i want to append or merge a files into One file and automatically,create a output file in the Output Path. So how can i do this?

Regards, Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
Author: Mahesh             
Posted Date: March 01, 2012     Points: 20   

Hi,
Put the above code provided in a for loop so that all files will be merged as,

foreach(string fileName in Directory.GetFiles("d:\\file","*.txt"))
{
// put above code
}

Hope this helps...

Regards,
Mahesh

Author: Narayanan             
Posted Date: March 05, 2012     Points: 20   

Hi,
Thanks for your reply.

Regards, Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

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