How to download a pdf file in cross platform xamarin.

Hi,

I am trying to download a file in xamarin by accessing a files in folder not included in the solution, but is present in the folder as uploaded files from user.
But some how it gets queued in the background and does not not show up on the notification header in emulator and remains queued and the paused.

**Example : **
public async void DownloadFile(string FileName)
{
await Task.Yield();

        await Task.Run(() =>
        {
            var downloadManager = CrossDownloadManager.Current;
            var file = downloadManager.CreateDownloadFile(FileName);
            downloadManager.Start(file, true);

            while (isDownloading)
            { 
                isDownloading = IsDownloading(file);
            }
        });

        if (!isDownloading)
        {
            await DisplayAlert("File Status", "File Downloded", "OK");
        }

    }
    public void AbortDownloading()
    {
        CrossDownloadManager.Current.Abort(File);
    }
    public bool IsDownloading(IDownloadFile File)
    {
        if (File == null) return false;

        switch (File.Status)
        {
            case DownloadFileStatus.INITIALIZED:
            case DownloadFileStatus.PAUSED:
            case DownloadFileStatus.PENDING:
            case DownloadFileStatus.RUNNING:
                return true;

            case DownloadFileStatus.COMPLETED:
            case DownloadFileStatus.CANCELED:
            case DownloadFileStatus.FAILED:
                return false;
            default:
                throw new ArgumentOutOfRangeException();
        }
    }

Best Answer

  • shamineshamine ✭✭
    Accepted Answer

    i found the solution, go to iis manager --> directory services --> and the enable . So the files become available to download

Answers

  • shamineshamine Member ✭✭
    Accepted Answer

    i found the solution, go to iis manager --> directory services --> and the enable . So the files become available to download

Sign In or Register to comment.