Click here to Skip to main content
15,885,900 members
Please Sign up or sign in to vote.
1.11/5 (4 votes)
Hi Dear All



Please anyone tell me How to copy all files from a folder in a web application to a folder in another web application in asp .net using c#.



Thank You all... :)
Posted
Comments
Leo Chapiro 4-Sep-14 8:36am    
What have you tried by your self, what was the problem?
MairajAhmed 5-Sep-14 8:28am    
File.Copy in System.IO namespace.

 
Share this answer
 
Comments
SubhashRokzzz 5-Sep-14 0:32am    
My Files are in a folder of an asp .net web appliction on client server and i would like to copy those files to a folder in an asp .net web application on my system .
In My point of view, you can't: The default permissions for the user your website is running under will almost certainly not allow you to access files in the root directory of your server, and your website cannot specify the storage location of a file on the client (or even if it is stored at all - that is up to the user)

For this we have indirect way the below code is retrieve file from DB Modify the Code based on your requirement

<![CDATA[<%  
    // Send a download file to the client given the filename.    
    string guid = Request.QueryString["file"];
    string fileName = "ERROR";
    byte[] data = new byte[] { 0, 0, 0, 0 };
    string strCon = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["DownloadDatabase"].ConnectionString;
    using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(strCon))
        {
        con.Open();
        string strcmd = "SELECT [iD] ,cn.[fileName],[description] ,[dataContent] ,[version] " +
                        "FROM dlContent cn " +
                        "WHERE cn.iD=@ID";
        using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(strcmd, con))
            {
            cmd.Parameters.AddWithValue("@ID", guid);
            using (System.Data.SqlClient.SqlDataReader r = cmd.ExecuteReader())
                {
                if (r.Read())
                    {
                    fileName = (string) r["filename"];
                    data = (byte[]) r["dataContent"];
                    }
                }
            }
        }
    Response.Clear();
    Response.AddHeader("Cache-Control", "no-cache, must-revalidate, post-check=0, pre-check=0");
    Response.AddHeader("Pragma", "no-cache");
    Response.AddHeader("Content-Description", "File Download");
    Response.AddHeader("Content-Type", "application/force-download");
    Response.AddHeader("Content-Transfer-Encoding", "binary\n");
    Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
    Response.BinaryWrite(data);
    Response.End();  
%>]]>
 
Share this answer
 
Save another applications directory path in your current applications config file and then using file.copy copy all the files from source to destination. if u want to move them them delete from current application after copying....
 
Share this answer
 
Use FTP, remember that a website could be hosted in a number of different ways, so you really don't want to get into specific about addresses, but connections can more easily be configuration items, which ultimately you can have different configurations for different environments (as could a path ... but ... just don't ;) )

Look at similar question here, Solution 3 will give you the code, it's pretty simple once you have the ftp server bit set up for the site.

How do I copy files from one web application to another in asp .net[^]
 
Share this answer
 
If both are in Same server it is easy.. if not.. create a WCF Service To Do your task
 
Share this answer
 

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