本文小編為大家詳細(xì)介紹“如何用C#的WinForm實(shí)現(xiàn)自動(dòng)更新程序”,內(nèi)容詳細(xì),步驟清晰,細(xì)節(jié)處理妥當(dāng),希望這篇“如何用C#的WinForm實(shí)現(xiàn)自動(dòng)更新程序”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來(lái)學(xué)習(xí)新知識(shí)吧。
創(chuàng)新互聯(lián)建站主營(yíng)浠水網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,重慶App定制開(kāi)發(fā),浠水h5小程序定制開(kāi)發(fā)搭建,浠水網(wǎng)站營(yíng)銷(xiāo)推廣歡迎浠水等地區(qū)企業(yè)咨詢(xún)
.NET Core 3.1
Visual Studio 2019
//xml文件http://localhost:5000/api/Update/
//Model public class UpdateModel { public string name { get; set; } public string version { get; set; } } public class UpdateModel_Out { public string url { get; set; } public ListupdateList { get; set; } }
//控制器 namespace AutoUpdate.WebApi.Controllers { [Route("api/[controller]/[Action]")] [ApiController] public class UpdateController : ControllerBase { [HttpGet] public JsonResult Index() { return new JsonResult(new { code = 10, msg = "success" }); } [HttpPost] public JsonResult GetUpdateFiles([FromBody] Listinput) { string xmlPath = AppContext.BaseDirectory + "UpdateList.xml"; XDocument xdoc = XDocument.Load(xmlPath); var files = from f in xdoc.Root.Element("files").Elements() select new { name = f.Attribute("name").Value, version = f.Attribute("version").Value }; var url = xdoc.Root.Element("url").Value; List updateList = new List (); foreach(var file in files) { UpdateModel model = input.Find(s => s.name == file.name); if(model == null || file.version.CompareTo(model.version) > 0) { updateList.Add(new UpdateModel { name = file.name, version = file.version }); } } UpdateModel_Out output = new UpdateModel_Out { url = url, updateList = updateList }; return new JsonResult(output); } [HttpPost] public FileStreamResult DownloadFile([FromBody] UpdateModel input) { string path = AppContext.BaseDirectory + "files\\" + input.name; FileStream fileStream = new FileStream(path, FileMode.Open); return new FileStreamResult(fileStream, "application/octet-stream"); } } }
讀到這里,這篇“如何用C#的WinForm實(shí)現(xiàn)自動(dòng)更新程序”文章已經(jīng)介紹完畢,想要掌握這篇文章的知識(shí)點(diǎn)還需要大家自己動(dòng)手實(shí)踐使用過(guò)才能領(lǐng)會(huì),如果想了解更多相關(guān)內(nèi)容的文章,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。