В этом проекте файл CSV загружается с использованием класса WebClient, а затем сохраняется в корневом каталоге, где его можно обрабатывать дальше.
Это код, который я написал до сих пор (игнорируйте комментарии, это было сделано только для меня, чтобы получить более четкое представление):
Код: Выделить всё
using System;
using System.IO;
using System.Net;
using System.Linq;
class FileDownloader
{
void FileHandling()
{
Console.WriteLine("Put in a name of a lifter");
string Lifter = Console.ReadLine().Replace(" ", "").ToLower(); // Makes sure that the lifters name is all
// in lower letters instead of caps which makes it easier for the link to find the stats
try
{
string OpenIPFUrl = $"https://www.openipf.org/api/liftercsv/{Lifter}";
using (WebClient client = new WebClient())
{
client.DownloadFile(OpenIPFUrl, $"{Lifter}.csv");
}
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
void DirectoryHandling()
{
DirectoryInfo d = new DirectoryInfo(@"C:\Users\Gebruiker\RiderProjects\ConsoleApp1");
FileInfo[] Files = d.GetFiles("*.csv");
string str = "";
foreach (FileInfo file in Files) // Checks if there is a certain .csv file in the root
{
str = str + ", " + file.Name;
Console.WriteLine(file);
}
// Look for a .csv file thats in the project root,
// if (file has been found, direct it directly to the lifters map
}
internal static void Main()
{
FileDownloader fileDownloader = new FileDownloader();
fileDownloader.FileHandling();
fileDownloader.DirectoryHandling();
}
}
Я создал каталог Lifters, в котором должны храниться файлы, но по какой-то причине загруженный файл CSV всегда оказывается в каталоге Debug/net9.0.
Есть ли способ переместить файл в каталог, который я упоминал ранее?>
Подробнее здесь: https://stackoverflow.com/questions/798 ... -directory
Мобильная версия