Basically i have a script to download a file from github into a specific folder and when i click the button that runs the code it tells me it doesnt have access to the path. Code. Using framework 4.8, c# visual form project
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Net;using System.IO;namespace BPRINSTALLER{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private static byte[] DownloadFile(string url) { // Create a new WebClient object using (var client = new WebClient()) { // Use the WebClient's DownloadData method to download the contents of the specified URL return client.DownloadData(url); } } private void button2_Click(object sender, EventArgs e) { // Initialize a string variable with the URL of a file on GitHub string fileUrl = "https://github.com/FowningFrog/burnout_mods/blob/main/350Z/VEH_PDSVK0B_AT.BIN"; // Call the DownloadFile method to download the contents of the file at the specified URL byte[] fileContents = DownloadFile(fileUrl); // Initialize a string variable with the file path where the downloaded file will be saved string filePath = @"C:\Users\UKGC\Downloads\test"; // Use the WriteAllBytes method of the File class to write the contents of fileContents to the specified file path File.WriteAllBytes(filePath, fileContents); } }}
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Net;using System.IO;namespace BPRINSTALLER{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private static byte[] DownloadFile(string url) { // Create a new WebClient object using (var client = new WebClient()) { // Use the WebClient's DownloadData method to download the contents of the specified URL return client.DownloadData(url); } } private void button2_Click(object sender, EventArgs e) { // Initialize a string variable with the URL of a file on GitHub string fileUrl = "https://github.com/FowningFrog/burnout_mods/blob/main/350Z/VEH_PDSVK0B_AT.BIN"; // Call the DownloadFile method to download the contents of the file at the specified URL byte[] fileContents = DownloadFile(fileUrl); // Initialize a string variable with the file path where the downloaded file will be saved string filePath = @"C:\Users\UKGC\Downloads\test"; // Use the WriteAllBytes method of the File class to write the contents of fileContents to the specified file path File.WriteAllBytes(filePath, fileContents); } }}
Any help is appreciated <3
Similar Threads
Recent Announcements
Continue the conversation
Join the Discord to ask follow-up questions and connect with the community
C
C#
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.