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

Time:04-07

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?

CodePudding user response:

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"));
  •  Tags:  
  • c#
  • Related