• 创建删除文件


    /// <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;
            }
  • 相关阅读:
    GET 请求和 POST 请求
    爬虫
    模板继承
    静态文件配置
    终端cmd创建django
    商城商品分类导航效果
    css样式
    视图部分
    django初识和路由
    【源码分析】cocos2dx的Action
  • 原文地址:https://www.cnblogs.com/sophiel/p/9584990.html
Copyright © 2020-2023  润新知