.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 a Files in C#.net

Posted By: Narayanan     Posted Date: March 05, 2012    Points:5   Category :C#
Hi friends,
How to append a files in the C#.net? I have a Input Folder and 4 txt files in the Input Folder. i want to merge/Append a files in the same folder and Appended files will delete after appending .

Folder name: Test
File Names are
1) 2012_03_05_05:50:30.txt
2) 2012_03_05_05:50:35.txt
3 ) 2012_03_05_05:50:40.txt
4 ) 2012_03_05_05:50:45.txt. here there are 4 files in the Test Folder . I want to append a files into 1st file and Automatically. 2nd,3rd,4th file should be deleted after Appending or merge a files .How can i achieve this?

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

Hi,
See the following code....

string sPath = "d:\\temp";
string sFileType = "*.txt";
string sAppendFile = "Append.txt";

foreach (string fileName in Directory.GetFiles(sPath, sFileType))
{
try
{
if (fileName != sAppendFile)
{
File.AppendAllText(Path.Combine(sPath, sAppendFile), File.ReadAllText(Path.Combine(sPath, fileName)));
File.Delete(Path.Combine(sPath, fileName));
}
}
catch (Exception ex)
{
Console.WriteLine("Error" + ex.Message );
}

}

think it may help you...

Regards,
Mahesh

Author: Rajesh             
Posted Date: March 10, 2012     Points: 20   

hi sir attach your C# file split and merging code

Download Attachment

Author: Mahesh             
Posted Date: March 12, 2012     Points: 20   

For what....?

Author: Sandip Narawade             
Posted Date: July 20, 2012     Points: 20   

This is for merging two tiff images



public void meregTiff(string[] files)
{
// creation of the document with a certain size and certain margins
iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0, 0, 0, 0);

// creation of the different writers
iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, new System.IO.FileStream(Server.MapPath("~/PDF/result.pdf"), System.IO.FileMode.Create));

// load the tiff image and count the total pages
foreach (string image in files)
{
string str =image.Substring(image.LastIndexOf("\\"));
System.Drawing.Bitmap bm = new System.Drawing.Bitmap(Server.MapPath("~/TiffImages" + str));
int total = bm.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page);

document.Open();
iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;
for (int k = 0; k < total; ++k)
{
bm.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, k);
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(bm, System.Drawing.Imaging.ImageFormat.Bmp);
// scale the image to fit in the page
img.ScalePercent(72f / img.DpiX * 100);
img.SetAbsolutePosition(0, 0);
cb.AddImage(img);
document.NewPage();
}
}
document.Close();
}

Author: recthor             
Posted Date: June 27, 2013     Points: 20   

I do this almost daily. I use an image merger driver found on the internet . Install it and it becomes a selectable merger option.Then you can merge PDFs or tiffs etc.into one in any program at all, including Adobe Acrobat . Just open the images, select merge, and choice the form you want, the task will be finished in several seconds. if you haven't found a good choice , you can have a try. best wishes.
http://www.rasteredge.com/how-to/csharp-imaging/tiff-merge/



Author: arronlee             
Posted Date: March 02, 2014     Points: 20   

I am using another Tiff processing tools instead of Adobe's products. Here are the tutorials about how to merge Tiff files using it: http://www.yiigo.com/guides/csharp/how-to-merge-tiff.shtml
I hope it helps. Good luck.

Next Tomorrow is Another Day .


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