0

I have a problem with my code. I want to download some files (I'm currently doing a patcher), but there are so many files, and I don't want to create a string for all of them.

I want to store the links in an array. But the debugger says there's and exception in WebClient. Here's my code (fájlNév means fileName and fájlNévAlap means baseFileName): UPDATED CODE:

<!-- language: lang-c# -->

        WebClient myWebClient = new WebClient();
        string[] remoteUrl = new string[2] { "https://www.dropbox.com/s/62tt9w194xefk7t/", " https://www.dropbox.com/s/spni307vmk4zng9/" };
        string[] fájlNév = new string[2] { "alut.dll", "DevIL.dll" };
        string fájlNévAlap = "BlackBox.dll", WebResource = null;

        for(int i = 0; i < remoteUrl.Length; i++) {
            for(int x = 0; x < fájlNév.Length; x++) {
                WebResource = remoteUrl[i] + fájlNév[x];
                MessageBox.Show(WebResource);
                myWebClient.DownloadFile(WebResource,fájlNév[x]);
            }
        }

What can I do? What is wrong?

4

2 に答える 2

4

多くのコメントがありますが、これに言及した人はいません。

MSDNをチェックしてください

public void DownloadFile(
    string address,
    string fileName
)

DownloadFileフォルダーではなくファイル名を期待します。

次のように変更してみてください:

myWebClient.DownloadFile(WebResource,"C://"  + fájlNév[x])

さらに、ルート フォルダーに直接書き込むとセキュリティ例外が発生する可能性があるため、特定のフォルダーに書き込むことをお勧めします。


さらに、Xantham 氏は、ループによって配列が範囲外の例外が発生することを指摘しました。

于 2013-02-18T21:03:57.943 に答える
2

Ofiris は、ファイル名が必要であるという主な答えを出しましたが、もっとありふれた問題もあり、注意を払う必要があると思いました。

for ループの最初の呼び出し:

for(int i = 0; i <= remoteUrl.Length; i++)

for(int x = 0; x <= fájlNév.Length; x++)

また、2 つのオブジェクト (0 と 1) のみの配列で remoteUrl[2] を見ようとすると、範囲外の配列の例外が発生します。

于 2013-02-18T21:19:09.513 に答える