Beispiel #1
0
 public ManagePage()
 {
     this.Load += new EventHandler(ManagePage_Load);
     siteConfig = new BLL.siteconfig().loadConfig(Utils.GetXmlMapPath("Configpath"));
 }
 public BLL_UpLoad()
 {
     siteConfig = new BLL_Siteconfig().loadConfig(Utils.GetXmlMapPath("Configpath"));
 }
Beispiel #3
0
 public UpLoad()
 {
     siteConfig = new BLL.siteconfig().loadConfig();
 }
Beispiel #4
0
 public ManagePage()
 {
     this.Load += new EventHandler(ManagePage_Load);
     siteConfig = new BLL.siteconfig().loadConfig();
 }
Beispiel #5
0
        public string Publish_News(string title, string content, string from, string add_time)
        {
            siteConfig = new BLL.siteconfig().loadConfig(Utils.GetXmlMapPath("Configpath"));
            //string filepath_template, string savePath, Model.article_news model_news
            //给公共方法传参,标题,图片,内容,生成新闻文件
            string savePath, filepath_template = string.Empty;//保存的服务端地址,模板路径

            filepath_template = Utils.GetMapPath(siteConfig.webpath + @"templates/news.html");

            string dirPath = GetUpLoadPath(); //上传目录相对路径
            string fileName = Utils.GetRamCode() + ".html"; //随机文件名
            //获得要保存的文件路径
            string serverFileName = dirPath + fileName;
            //物理完整路径
            string toFileFullPath = Utils.GetMapPath(dirPath);
            //检查有该路径是否就创建
            if (!Directory.Exists(toFileFullPath))
            {
                Directory.CreateDirectory(toFileFullPath);
            }
            //保存的服务端地址
            savePath = toFileFullPath + fileName;
            Encoding code = Encoding.GetEncoding("gb2312");
            StreamReader sr = null;
            StreamWriter sw = null;
            string str = null;

            //读取
            try
            {
                sr = new StreamReader(filepath_template, code);
                str = sr.ReadToEnd();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                sr.Close();
            }

            //根据时间自动重命名,扩展名也可以自行修改

            str = str.Replace("$title$", title) //替换Title
            .Replace("$content$", content) //替换content
            .Replace("$resource$", from) //来源
            .Replace("$datetimes$", add_time); //时间
            //.Replace("$Image$", model_news.img_url); //图片

            //生成静态文件
            try
            {
                sw = new StreamWriter(savePath, false, code);
                sw.Write(str);
                sw.Flush();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                sw.Close();
            }
            return serverFileName;
        }