© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
3 replies
Remaetanju

Forms ProgressBar with MegaApiClient download

using thoses resources:
https://gpailler.github.io/MegaApiClient/articles/samples.html
https://gpailler.github.io/MegaApiClient/articles/faq.html

=> download a file hosted by mega & show a forms progress bar

- the download is NOT ASYNC
- c# 6.0

the download works
i'm not sure how to adapt the progress bar system from mega to a windowsforms progress bar
internal static class Program
{
    private const string packurl = "https://mega.nz/file/R1pgBAAI#CDFU6xx9EwCEZJ1Z0vKfl_o9DNtPBNjllpuAVZ38nn4";
    [STAThread]
    static void Main()
    {
ApplicationConfiguration.Initialize();
        // downloaded zip name
        string LCGamePath = "F:\\Games\\Steam\\steamapps\\common\\Lethal Company";
        string packname = "MedalCompany.zip";
        // setupprogress bar
        ProgressBar pBar1 = new();
        // Display the ProgressBar control.
        if (pBar1 == null)
            return;
        pBar1.Visible = true;
        // Set Minimum to 1 to represent the first file being copied.
        pBar1.Minimum = 1;
        // Set Maximum to the total number of files to copy.
        pBar1.Maximum = 100;
        // Set the initial value of the ProgressBar.
        pBar1.Value = 1;
        // Set the Step property to a value of 1 to represent each file being copied.
        pBar1.Step = 1;
        // MegaApi Anonymous login
        MegaApiClient client = new MegaApiClient();
        client.LoginAnonymous();
        Uri fileLink = new Uri(packurl);
        INode node = client.GetNodeFromLink(fileLink);

        void performstep()
        {
            pBar1.PerformStep();
            pBar1.Show();
        }
        using (var downloadStream = client.Download(node))
        using (var progressionStream = new ProgressionStream(downloadStream, x => performstep()))

        using (var fileStream = new FileStream(LCGamePath + "\\" + packname, FileMode.Create))
        { progressionStream.CopyTo(fileStream);
        }
        client.Logout();
    }
}
internal static class Program
{
    private const string packurl = "https://mega.nz/file/R1pgBAAI#CDFU6xx9EwCEZJ1Z0vKfl_o9DNtPBNjllpuAVZ38nn4";
    [STAThread]
    static void Main()
    {
ApplicationConfiguration.Initialize();
        // downloaded zip name
        string LCGamePath = "F:\\Games\\Steam\\steamapps\\common\\Lethal Company";
        string packname = "MedalCompany.zip";
        // setupprogress bar
        ProgressBar pBar1 = new();
        // Display the ProgressBar control.
        if (pBar1 == null)
            return;
        pBar1.Visible = true;
        // Set Minimum to 1 to represent the first file being copied.
        pBar1.Minimum = 1;
        // Set Maximum to the total number of files to copy.
        pBar1.Maximum = 100;
        // Set the initial value of the ProgressBar.
        pBar1.Value = 1;
        // Set the Step property to a value of 1 to represent each file being copied.
        pBar1.Step = 1;
        // MegaApi Anonymous login
        MegaApiClient client = new MegaApiClient();
        client.LoginAnonymous();
        Uri fileLink = new Uri(packurl);
        INode node = client.GetNodeFromLink(fileLink);

        void performstep()
        {
            pBar1.PerformStep();
            pBar1.Show();
        }
        using (var downloadStream = client.Download(node))
        using (var progressionStream = new ProgressionStream(downloadStream, x => performstep()))

        using (var fileStream = new FileStream(LCGamePath + "\\" + packname, FileMode.Create))
        { progressionStream.CopyTo(fileStream);
        }
        client.Logout();
    }
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

❔ Color of a progressBar in Windows Forms
C#CC# / help
3y ago
❔ Panel with Datagridview problem (forms)
C#CC# / help
3y ago
✅ Progressbar progression over taskbar icon without nuget
C#CC# / help
2y ago
Help with c# slider in forms
C#CC# / help
3y ago