locked
How to determine file size of a downloadable file URL?

    Question

  • Hi,

    I want to determine a file size before downloading it. Is there any way?

    With Android platform, I can do that via HttpURLConnection class. Like this:

    HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
    String contentType = httpConn.getContentType();
    int contentLength = httpConn.getContentLength();

    Cheers,

    Vu Tran


    Vu Tran

    Friday, March 27, 2015 10:10 AM

Answers

All replies

  • Please try to follow below link. It might be help you.

    http://www.c-sharpcorner.com/Blogs/3524/

    Friday, March 27, 2015 10:40 AM
  • Please try to follow below link. It might be help you.

    http://www.c-sharpcorner.com/Blogs/3524/


    Hi Imtiyazk,

    Thanks for your info, but the solution on that blog not work for Windows Phone runtime 8.1. Class System.Net.WebClient does not support on Windows Phone runtime 8.1.

    Sincerely,

    Vu Tran

    Vu Tran

    Saturday, March 28, 2015 2:30 AM
  • Hi Vu_Tran,

    Not sure if its too late to reply but just have an idea, we can use background downloader to test the size, here I found a blog: http://blogs.msdn.com/b/pakistan/archive/2014/09/25/a-simple-backgrounddownloader-driven-user-control-implementation-for-windows-store.aspx

    The download percentage comes from  DownloadProgress = (bytesRecieved / totalBytesToReceive) * 100; we should be able to get the total file size from: DownloadOperation.Progress.TotalBytesToReceive

    Later if you do not need that, cancel the background download task..

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, April 09, 2015 9:42 AM
    Moderator