我是网络编程的新手,很抱歉这样的问题。我使用WebClient.DownloadFile(string fileAdress, string fileName)
方法下载文件。我从fileName
获得fileAdress
(即www.somelink.com/file.txt => file.txt)。而现在,我需要获得该文件的完整路径。如果它是桌面应用程序,我会以某种方式找到它。但现在,情况并不为我所知。
答案 0 :(得分:0)
下载的文件应保存在当前目录中。即,
Directory.GetCurrentDirectory()
示例:
using System.IO;
using System.Net;
var uri = new Uri("http://example.com/somefile.txt");
string filename = "somefile.txt";
new WebClient().DownloadFile(uri, filename);
string filePath = Path.Combine(Directory.GetCurrentDirectory(), filename);