Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why can't I download a .jar file using Webclient

I’m trying to make a simple Minecraft Mod installer and whenever I DownloadString something that is a .jar and try to DownloadFile it, it says that its illegal path. Is there a way around it or does it just accept .txt .exe along that.

var Mod = wc.DownloadString("Link to download that is .jar");

wc.DownloadFile(Mod, @"C:\Users\" + Environment.UserName + @"\AppData\Roaming\.minecraft\mods\Mod.jar");

That’s the code I’m currently using worked fine for me when I was using .exe and .txt files but doesn’t seem to work on .jar. Any work arounds?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The DownloadFile method documentation says

Downloads the resource with the specified URI to a local file. C#

public void DownloadFile (Uri address, string fileName);

address:Uri

The URI specified as a String, from which to download data.

fileName:String

The name of the local file that is to receive the data.

https://docs.microsoft.com/en-us/dotnet/api/system.net.webclient.downloadfile?view=net-6.0

But in your example looks like you’re first downloading the link as a string and then calling DownloadFile with that instead of the original Uri.

i.e. looks like you should be doing

wc.DownloadFile("Link to download that is .jar", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ".minecraft\mods\Mod.jar"));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading