How to download direct from TXT file

Asked

Viewed 143 times

0

I uploaded a file to a WEB server, but when I use this code:

 WebClient update = new WebClient();
string Teste = update.DownloadString("http://testexxx.000webhostapp.com/teste.txt");

Returns this error: Configurationerrorsexception: Unrecognized element.

Because it is not downloading the file directly, because when it opens the file on the site it shows what is inside and does not download, how can I fix it?

  • What would be your update? could put more code ? is a Webclient ?

  • 1

    update and Webclient, I will update the code

  • 1

    TXT is a file has to do different

  • How could I do it? But it had to be TXT

  • 1

    @Thiagoloureiro is logical that it is a Webclient, given the fact that it was declared as Webclient update.

  • 1

    Perozzo, did not have the declaration before rsrs

  • 2

    @Thiagoloureiro Sorry mate :( Thanks Rovann.

  • 1

    @Perozzo ta forgiven :P

Show 3 more comments

1 answer

1


Set the header for WebClient for Text/Plain:

using (WebClient wc = new WebClient())
{
    wc.Headers.Set("Content-Type", "text/plain");
    url = "http://www.dominio.com.br/teste.txt";
    string retorno = wc.DownloadString(url);
}

Edit:

Using the Pastebin link:

using (WebClient wc = new WebClient())
{
    //retorno = wc.DownloadString(url);

    url = "https://pastebin.com/raw/xdTbdD5P";
    wc.Headers.Set("Content-Type", "text/plain");
    retorno = wc.DownloadString(url);

}

Upshot:

inserir a descrição da imagem aqui

  • The error continues The configuration system failed to initialize' Configurationerrorsexception: Unrecognized element.

  • 1

    then is another problem, here it worked 100%, if you have to release an example url, we can test

  • when accessing the url you get this: http://prntscr.com/jo5nk2

  • @Slinidy Please place the entire method that is running the given code.

  • I’m running on a button, what’s inside it is this code that he answered

  • In Pastebin you are also giving error: https://pastebin.com/raw/xdTbdD5P

  • what is this in Pastebin ? it seems to me, came the contents of txt

  • Yes is the content of TXT and is the same as the site that changes is the URL

  • look at the editing, working too

  • http://prntscr.com/jo63ed

  • clearly not an issue with Webclient, in a quick search I saw similar problems caused by app.config. Give more information about your solution. Winforms, web, wpf, what we are talking about ?

  • 1

    Winforms, you have Cefsharp and Materialskinmanager and my appconfig looks like this: http://prntscr.com/jo670i

  • 1

    The problem is in my own project, I’ll see what it is. The code is working

Show 8 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.