Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在web目录中循环多个文件并下载_C#_Asp.net_Directory_Webserver_Webclient - Fatal编程技术网

C# 在web目录中循环多个文件并下载

C# 在web目录中循环多个文件并下载,c#,asp.net,directory,webserver,webclient,C#,Asp.net,Directory,Webserver,Webclient,我试图从我的web目录(在IIS上)下载图像文件,所以我尝试使用web客户端通过循环下载这些文件。我有两个应用程序,一个是我部署的web应用程序,另一个是WPF应用程序,我尝试从web应用程序下载文件。这是我的密码: public StartWindow() { InitializeComponent(); string fileUploadDirectory = ConfigurationManager.

我试图从我的web目录(在IIS上)下载图像文件,所以我尝试使用web客户端通过循环下载这些文件。我有两个应用程序,一个是我部署的web应用程序,另一个是WPF应用程序,我尝试从web应用程序下载文件。这是我的密码:

     public StartWindow()
        {
            InitializeComponent();        
            string fileUploadDirectory = ConfigurationManager.AppSettings.Get("path"); 
          //  string fullpath = System.IO.Path.Combine(fileUploadDirectory, daoWordPuzzle.GetfileURL().Substring(2)); // removes  ( ~/ ) . 
 string fullpath = "http://localhost/iStellarMobile_deploy/Designs/";
                DirectoryInfo d = new DirectoryInfo(fullpath);
                FileInfo[] Files = d.GetFiles("*.png");
                foreach (FileInfo file in Files)
                {
                    string root = file.DirectoryName;
                    DownloadFile(root);
                }
        }

   protected void DownloadFile(string urlAddress)
    {
        client = new WebClient();     
        string currentpath = System.IO.Directory.GetCurrentDirectory() + @"\ImagesTest"; // Save under ImagesTest folder.
        client.DownloadFile(urlAddress, currentpath);    
    }
图像在设计文件夹中。。这就是我想下载的。。。 然后在我的App.config中:

  <appSettings>
<add key="path" value="http://localhost/iStellarMobile_deploy" />

我部署的web位于C:/inetpub/wwwroot上。那么我做错了吗?我试图通过在目录中循环下载多个文件

您试图通过http访问文件,而使用的是为文件系统设计的处理程序…抱歉,我不明白您的意思也不确定我是否可以解释,但这根本不起作用…为什么会这样?因为我试图访问http的目录?DirectoyInfo和Stuff只允许你访问应用程序文件?我想Stefan是想说http不同于ftp。
protected void DownloadData(string strFileUrlToDownload)
    {
        WebClient client = new WebClient();
        byte[] myDataBuffer = client.DownloadData(strFileUrlToDownload);         

        MemoryStream storeStream = new MemoryStream();

        storeStream.SetLength(myDataBuffer.Length);
        storeStream.Write(myDataBuffer, 0 , (int)storeStream.Length);

        storeStream.Flush();

        string currentpath = System.IO.Directory.GetCurrentDirectory() + @"\Folder"; //folder to contain files.

        using (FileStream file = new FileStream(currentpath, FileMode.Create, System.IO.FileAccess.ReadWrite))
        {
            byte[] bytes = new byte[storeStream.Length];
            storeStream.Read(bytes, 0, (int)storeStream.Length);
            file.Write(myDataBuffer, 0, (int)storeStream.Length);
            storeStream.Close();
        }

        //The below Getstring method to get data in raw format and manipulate it as per requirement
        string download = Encoding.ASCII.GetString(myDataBuffer);


    }