Forum Xamarin.Forms

How to download a file in Xamarin Forms and store it in the device storage ?

AsfendYarAsfendYar USMember ✭✭✭

Recently I've tried the nugget package that is
https://github.com/SimonSimCity/Xamarin-CrossDownloadManager
By using this I've successfully download the file but the problem is where this file is stored ?
I cannot see it anywhere in my device ...

Best Answer

Answers

  • AsfendYarAsfendYar USMember ✭✭✭

    Hello David !
    Where will I put the following code

    CrossDownloadManager.Current.PathNameForDownloadedFile = new System.Func<IDownloadFile, string> (file => {

    if IOS

            string fileName = (new NSUrl(file.Url, false)).LastPathComponent;
            return Path.Combine(Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments), fileName);
    

    elif ANDROID

            string fileName = Android.Net.Uri.Parse(file.Url).Path.Split('/').Last();
            return Path.Combine (ApplicationContext.GetExternalFilesDir (Android.OS.Environment.DirectoryDownloads).AbsolutePath, fileName);
    

    else

            string fileName = '';
            return Path.Combine(Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments), fileName);
    

    endif

        });
    
  • SomaSekharK.0166SomaSekharK.0166 USMember

    Hi AsfendYar could you please sample of this implementation if you have any.

  • Mini_TitanMini_Titan Member ✭✭

    Thank @Rohit_Arnav

  • Rohit_ArnavRohit_Arnav USMember ✭✭

    I am glade you like the solution @Mini_Titan

Sign In or Register to comment.