2

I'm kind of newbie and i'm working on a background transfer feature to download files. It's for windows phone 7. But the problem is files over 100 MB can't be downloaded with "Transfer Preference = Allow Battery" and if i use "Transfer Preference = None" the phone must be connected to a power source in order to transfer (any file size). So far this is what i have tried but it just doesn't work with files over 100MB. Any help, or suggestion would be great. Thanks!

    private void downloadTrigger()
    {
        string transferFileName = urlTextBox.Text;
        var transferUri = new Uri(Uri.EscapeUriString(transferFileName), UriKind.Absolute);

        BackgroundTransferRequest transferRequest = new BackgroundTransferRequest(transferUri);
        transferRequest.Method = "GET";

        string downloadFile = transferFileName.Substring(transferFileName.LastIndexOf("/") + 1);
        Uri downloadUri = new Uri("shared/transfers/" + downloadFile, UriKind.Relative);
        transferRequest.DownloadLocation = downloadUri;
        transferRequest.Tag = downloadFile;

        if (transferRequest.TotalBytesToReceive >= 104857600)
        {
            try
            {
                transferRequest.TransferPreferences = TransferPreferences.None;
                MessageBox.Show("For files over 100MB an external power is required to start copy.", "News box", MessageBoxButton.OK);
                BackgroundTransferService.Add(transferRequest);
                feedbackTextBlock.Text = "Queueing " + downloadFile;
                return;
            }
            catch
            {
            }
        }

        try
        {
            transferRequest.TransferPreferences = TransferPreferences.AllowBattery;
            BackgroundTransferService.Add(transferRequest);
            feedbackTextBlock.Text = "Copying " + downloadFile;
        }
        catch
        {
        }
    }
freddyjdc
  • 53
  • 5
  • What exactly happens if you try to download those big files? Any exceptions? Does the code step into the catch? Set a break-point at the first curly brace in the catch-block, because in your code your doing something like VB "ON ERROR RESUME NEXT"! – Alexander Schmidt Jul 08 '12 at 11:13
  • It just get the file name and store it but it doesn't download the actual file. No errors or exceptions. – freddyjdc Jul 08 '12 at 11:20
  • Please try to hook on the events of the BackgroundTransferRequest (TransferProgressChanged and TransferStatusChanged). Is the code stepping into this events? – Alexander Schmidt Jul 08 '12 at 11:47
  • I'm working with MS SDK Background transfer. So, one page add the files to background through the code above and another page handle TransferProgressChanged and TransferStatusChanged. The thing is, TotalBytesToReceive value is populated after BackgroundTransferService.Add(). – freddyjdc Jul 13 '12 at 02:26
  • I'll keep trying if i find a solution i'll add it here. Thanks. – freddyjdc Jul 13 '12 at 02:27
  • Sorry for late repply. So you mean, you will loose the state? You could use a singleton class to hold the instances and hook up to the events. Or am I getting something wrong? – Alexander Schmidt Jul 16 '12 at 07:29

0 Answers0