Copy only particular extension files from one folder to another in C#

Vasanth
 
on Sep 25, 2012 06:35 AM
9948 Views

Hi

I have a list of word document in a folder.

I need the following to acheive it.

        - I need to read and edit the file(word) file and save it in another location one by one.

 

Can any one please give me solution for this.

Thanks.

 

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
Mudassar
 
on Sep 25, 2012 06:36 AM

This way

        string[] files = Directory.GetFiles(Server.MapPath("~/Folder1/"), "*.doc");
        foreach(string file in files)
        {
            File.Copy(file, Server.MapPath("~/Folder2/") + Path.GetFileName(file));
        }

        files = Directory.GetFiles(Server.MapPath("~/Folder1/"), "*.docx");
        foreach (string file in files)
        {
            File.Copy(file, Server.MapPath("~/Folder2/") + Path.GetFileName(file));
        }