-6
Uri uri = new Uri("http://rotter.net/scoopscache.html");
client.Encoding = System.Text.Encoding.GetEncoding(1255);
//page = client.DownloadString("http://rotter.net/scoopscache.html");
page = client.DownloadFileAsync(uri, @"myhtml.html");
listsext.Ext(page);

If I'm using DownloadString, it will assign the html content to page. I want the page to contain the file name, so I tried to use DownloadFileAsync but I'm getting error on this line:

Error   2   Cannot implicitly convert type 'void' to 'string'
demongolem
  • 9,474
  • 36
  • 90
  • 105
  • Well, that's because DownloadFileAsync returns void, not a string. And "Async" doesn't mean it's going to give you the filename, it means it's going to do the work asynchronously. What filename do you want it to contain? `scoopscache.html`? – mason Jul 21 '14 at 14:52
  • Yes scoopscache.html or any other file name i will give but yes the downloaded file name. – Daniel Barnatan Jul 21 '14 at 14:53
  • 1
    You seem to know what file name it is without having to actually download it. Why can't you just pull it out of this line: `Uri uri = new Uri("http://rotter.net/scoopscache.html");`? – mason Jul 21 '14 at 14:56

1 Answers1

2

Explanation about the error:

WebClient.DownloadFileAsync

public void DownloadFileAsync(
    Uri address,
    string fileName
)

It doesn't return anything (void) and you are passing this to listsext! Ofcourse you will get an Exception:

Cannot implicitly convert type 'void' to 'string'

What you want to achieve: (my guess, not much information given)

You want to have the filename, you don't need to download it.

Uri u = new Uri("http://rotter.net/scoopscache.html")
filename = Path.GetFileName(u.LocalPath);

See here: Get file name from URI string in C#

Community
  • 1
  • 1
RvdK
  • 19,580
  • 4
  • 64
  • 107
  • There is [an overload](http://msdn.microsoft.com/en-us/library/ms144196(v=vs.110).aspx) to this method that only requires 2 parameters. – mason Jul 21 '14 at 14:57
  • @mason: thanks, I missed the overload version of it. Updated the answer. – RvdK Jul 21 '14 at 15:00