Search code examples
c#system.net.webexception

How do I fix System.Net.WebException: 'The filename, directory name, or volume label syntax is incorrect


I am trying to create a bootstrapper for a program and the error "System.Net.WebException: 'The filename, directory name, or volume label syntax is incorrect " Keeps popping up.

I have been stuck on this problem and have been guessing how to solve the problem.

String pname = "Fredysploit_v2";
String dlink = "https://pastebin.com/V5NcE09n";
string title = @"Title ";
Console.Title = pname + " Bootstrapper";

Console.ForegroundColor = ConsoleColor.Blue;
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(title);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Downloading new Files...");
WebClient wc = new WebClient();
string key = wc.DownloadString(dlink);
string path = @"Update\" + pname + ".exe";
System.Net.WebClient Dow = new WebClient();
string patch = (@"Update");
Directory.CreateDirectory(patch);
//My problem ↓
Dow.DownloadFile(key, path);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(pname + " Downloaded | Updated!");
Console.WriteLine($"Now open " + patch + " and Run " + pname + ".exe");
Console.ReadKey();

I expected the outcome to download the file off the text which is a link on pastebin but, the actual outcome was "System.Net.WebException: 'The filename, directory name, or volume label syntax is incorrect".


Solution

  • The problem is you are getting the entire page of HTML form pastebin not the URL you are looking for. As @Jon Skeet mentioned in comments, try using https://pastebin.com/raw/V5NcE09n as dlink so it shows as follows:

    String dlink = "https://pastebin.com/raw/V5NcE09n";
    

    The updated code solution is below:

    String pname = "Fredysploit_v2";
    String dlink = "https://pastebin.com/raw/V5NcE09n";
    string title = @"Title ";
    Console.Title = pname + " Bootstrapper";
    
    Console.ForegroundColor = ConsoleColor.Blue;
    Console.ForegroundColor = ConsoleColor.Cyan;
    Console.WriteLine(title);
    Console.ForegroundColor = ConsoleColor.Green;
    Console.WriteLine("Downloading new Files...");
    WebClient wc = new WebClient();
    string key = wc.DownloadString(dlink);
    string path = @"Update\" + pname + ".exe";
    System.Net.WebClient Dow = new WebClient();
    string patch = (@"Update");
    Directory.CreateDirectory(patch);
    
    Dow.DownloadFile(key, path);
    Console.ForegroundColor = ConsoleColor.Green;
    Console.WriteLine(pname + " Downloaded | Updated!");
    Console.WriteLine($"Now open " + patch + " and Run " + pname + ".exe");
    Console.ReadKey();