Limit WebClient DownloadFile maximum file size

后端 未结 2 1389
無奈伤痛
無奈伤痛 2021-01-03 08:50

In my asp .net project, my main page receives URL as a parameter I need to download internally and then process it. I know that I can use WebClient\'s DownloadFile method ho

2条回答
  •  青春惊慌失措
    2021-01-03 09:24

    var webClient = new WebClient();
    client.OpenRead(url);
    Int64 bytesTotal = Convert.ToInt64(client.ResponseHeaders["Content-Length"]);
    

    Then you decide if bytesTotal is within the limit

提交回复
热议问题