样式版本批量处理,使用文件修改最后日期作为版本号参数

Posted 李文平

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了样式版本批量处理,使用文件修改最后日期作为版本号参数相关的知识,希望对你有一定的参考价值。

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;

namespace CRM3.Common
{
public class AutoVersion
{
private static string SetVersion(string filePath)
{
string verFilePath = filePath;
string serverPath = HttpContext.Current.Server.MapPath(filePath);
if (File.Exists(serverPath))
{
verFilePath = filePath + "?" + File.GetLastWriteTime(serverPath).ToString("yyMMddHHmmss");
//verFilePath = filePath.Insert(filePath.LastIndexOf(‘.‘),
// string.Concat(".", File.GetLastWriteTime(serverPath).ToString("yyMMddHHmmss")));
}
return verFilePath;
}

public static string CssLink(params string[] filePath)
{
var sb = new StringBuilder();
Array.ForEach(filePath, f => sb.AppendLine(string.Format(@"<link rel=""stylesheet"" type=""text/css"" href=""{0}"" />",
SetVersion(f))));
return sb.ToString();
}
public static string javascriptLink(params string[] filePath)
{
var sb = new StringBuilder();
Array.ForEach(filePath, f => sb.AppendLine(string.Format(@"<script type=""text/javascript"" src=""{0}""></script>",
SetVersion(f))));
return sb.ToString();
}
}
}

以上是关于样式版本批量处理,使用文件修改最后日期作为版本号参数的主要内容,如果未能解决你的问题,请参考以下文章

解决项目迭代css,js文件缓存问题

Linux下批量修改文件名

百度云盘批量修改文件名称方法

获取文件最后修改日期(资源管理器值不是 cmd 值)

批量修改文件名(find & rename & sed)

sublime text怎么批量修改