63 lines
1.8 KiB
C#
63 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
|
|
namespace 報到系統.Forms
|
|
{
|
|
public partial class Home : PageBase
|
|
{
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
public string LatestClientPackage()
|
|
{
|
|
var latestClientPackage = GetLatestClientPackageFileName();
|
|
if (!string.IsNullOrEmpty(latestClientPackage))
|
|
{
|
|
return ResolveUrlWithSysVer(string.Format("~/Assets/Downloads/{0}", latestClientPackage));
|
|
}
|
|
return string.Empty;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取得最新的客戶端安裝包檔案名稱
|
|
/// 從 Assets/Downloads 目錄下查找 "報到系統客戶端_*.zip" 檔案
|
|
/// 按檔名排序取最大的那一個
|
|
/// </summary>
|
|
private string GetLatestClientPackageFileName()
|
|
{
|
|
try
|
|
{
|
|
string downloadDir = Server.MapPath("~/Assets/Downloads/");
|
|
|
|
if (!Directory.Exists(downloadDir))
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
DirectoryInfo dirInfo = new DirectoryInfo(downloadDir);
|
|
FileInfo[] files = dirInfo.GetFiles("報到系統客戶端_*.zip");
|
|
|
|
if (files.Length == 0)
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
// 按檔名排序,取最後一個(最大的那個)
|
|
string latestFileName = files.OrderBy(f => f.Name).LastOrDefault()?.Name;
|
|
|
|
return latestFileName ?? string.Empty;
|
|
}
|
|
catch
|
|
{
|
|
return string.Empty;
|
|
}
|
|
}
|
|
}
|
|
} |