/// <summary>
/// 创建文件
/// </summary>
/// <param name="p_posId"></param>
/// <param name="p_posKey"></param>
/// <param name="p_content"></param>
/// <param name="p_jsonCode"></param>
private static void CreateFile(int p_posId, string p_posKey, string p_content, ReturnJsonCode p_jsonCode)
{
StreamWriter sw = null;
try
{
string strJsPath = HttpContext.Current.Server.MapPath(string.Format("/js/{0}/", p_posId / 1000));
if (!Directory.Exists(strJsPath))
{
Directory.CreateDirectory(strJsPath);
}
sw = new StreamWriter(string.Format("{0}{1}.js", strJsPath, p_posKey), false, Encoding.UTF8);
sw.Write(p_content);
p_jsonCode.code = 1;
p_jsonCode.msg = "脚本生成成功";
p_jsonCode.data = string.Format("//{0}/js/{1}/{2}.js", ConfigurationManager.AppSettings["conDomain_a_com"], p_posId / 1000, p_posKey);
}
catch (Exception ex)
{
p_jsonCode.msg = string.Format("脚本生成失败,错误内容:{0}", ex.Message);
}
finally
{
if (sw != null)
{
sw.Close();
}
}
}
/// <summary>
/// 删除广告位脚本文件
/// </summary>
/// <param name="p_posId">广告位ID</param>
/// <param name="p_posKey">广告位objectId</param>
/// <returns></returns>
public static ReturnJsonCode DelPosJs(int p_posId, string p_posKey)
{
ReturnJsonCode jsonCode = new ReturnJsonCode();
if (p_posId <= 0 || string.IsNullOrWhiteSpace(p_posKey))
{
jsonCode.msg = "参数错误";
return jsonCode;
}
string strJsPath = HttpContext.Current.Server.MapPath(string.Format("/js/{0}/{1}.js", p_posId / 1000, p_posKey));
if (File.Exists(strJsPath))
{
try
{
File.Delete(strJsPath);
jsonCode.code = 1;
jsonCode.msg = "删除广告文件成功";
}
catch (Exception ex)
{
jsonCode.msg = string.Format("删除广告文件失败,错误内容:{0}", ex.Message);
}
}
else
{
jsonCode.msg = "广告文件不存在";
}
return jsonCode;
}