我正在尋找一種方式上的文件夾的名稱,我得到它位於(例如)http://example.com/download/"foldername here"
如何獲得一個網站
這樣做的原因文件夾名是因爲我有交流#程序,它總是下載一個.zip文件,如果你沒有準備好,但是目前它不會下載一個新版本。
例如:目前它從http://example.com/download/1.0/file.zip
下載,如果你已經有了它檢查的文件夾,它不會下載它,但是如果你有這個文件夾,它將不會從http://example.com/download/2.0/file.zip
下載,其中包含新版本。我創建了一個包含當前版本的文件,但是如何讓我的程序根據最新版本所在的文件夾來檢查該文件?
編輯:我重寫了我的代碼,因此它首先下載version.txt
文件並讀取它的內容,其中包含最新版本的下載。
代碼:
if (radUseFile.Checked)
{
//get latest version on website
WebClient modver = new WebClient();
modver.UseDefaultCredentials = true;
modver.DownloadFile("http://www.example.com/download/version.txt", tempdir _
+ "version.txt");
using (StreamReader ver = new StreamReader(tempdir + "version.txt"))
{
siteversion = ver.ReadToEnd();
}
File.Delete(tempdir + "version.txt");
if (Directory.Exists(folder))
{
if (File.Exists(folder + "\\version.txt"))
{
using (StreamReader sr = new StreamReader(folder + "\\version.txt"))
{
latestversion = sr.ReadToEnd();
}
if (latestversion != siteversion)
{
uptodate = false;
}
else
{
uptodate = true;
}
}
}
else
{
uptodate = false;
}
if (!uptodate)
{
//download and extract the files
WebClient downloader = new WebClient();
label4.Text = "Downloading full client. May take a while";
this.Update();
downloader.UseDefaultCredentials = true;
downloader.DownloadFile("http://www.example.com/download" + siteversion _
+ "/zipfile.zip", templocation + "zipfile.zip");
label4.Text = "Extracting...";
Shell32.Shell sc = new Shell32.Shell();
Directory.CreateDirectory(tempdir);
Shell32.Folder output = sc.NameSpace(tempdir);
Shell32.Folder input = sc.NameSpace(tempdir + "zipfile.zip");
output.CopyHere(input.Items(), 4);
label4.Text = "Cleaning up...";
File.Delete(tempdir + "zipfile.zip");
new Microsoft.VisualBasic.Devices.Computer().FileSystem.CopyDirectory(tempdir,_
folderlocation, true);
Directory.Delete(tempdir, true);
uptodate = true;
}
}
else
{
uptodate = true;
}
這適用於現在,但我敢肯定,這個代碼可以改善,或者它是如何發生的最新版本的整個方法
Url路徑不必映射到物理路徑。例如,今天'http:// foo.bar/download/mostrecent /'可以映射到'3.0',明天'4.0'。 – I4V
你想獲得'http:// foo.bar/download /'中所有'文件夾'的列表嗎? –
@ I4V我一直希望有這樣的事情,但我怎麼才能得到那個工作呢?通過製作一個重定向到最新版本的額外文件夾? – Yorrick