如何将所有文件从Web应用程序中的一个文件夹复制/移动到asp.net中的另一个Web应用程序 [英] How do I copy /move all files from one folder in a web application to another web application in asp .net

查看:57
本文介绍了如何将所有文件从Web应用程序中的一个文件夹复制/移动到asp.net中的另一个Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨亲爱的所有







请有人告诉我如何从文件夹中复制所有文件在Web应用程序中使用c#在asp.net中的另一个Web应用程序中的文件夹中。







谢谢大家...... :)

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... :)

推荐答案

参考此链接



将文件从一个位置复制到另一个位置并在放置时间戳后重命名 [ ^ ]


在我的观点中,您不能:您网站运行的用户的默认权限几乎肯定不会允许您访问服务器的根目录,您的网站无法在客户端上指定文件的存储位置(甚至如果它是存储的 - 这取决于用户)



为此我们有间接方式以下代码是从DB检索文件修改代码基于你的要求



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();  
%>]]>


在当前应用程序配置文件中保存另一个应用程序目录路径,然后使用file.copy复制所有文件从源头到目的地。如果您想移动它们,则在复制后从当前应用程序中删除....
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....


这篇关于如何将所有文件从Web应用程序中的一个文件夹复制/移动到asp.net中的另一个Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆