Ejemplo n.º 1
0
        /// <summary>
        /// 保存子模板
        /// </summary>
        /// <param name="sub"></param>
        void SaveSub()
        {
            using (FileStream fs = File.Open(FileName, FileMode.CreateNew, FileAccess.Write))
            {
                using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
                {
                    List <string> tags = new List <string>();
                    foreach (WeControl c in Controls)
                    {
                        if (!tags.Contains(c.TagName))
                        {
                            tags.Add(c.TagName);
                        }
                    }

                    foreach (string c in tags)
                    {
                        sw.WriteLine(string.Format("<%@ Register Src=\"~" + Constants.ControlUrlPath + "/{0}.ascx\" TagName=\"{0}\" TagPrefix=\"wec\" %>", c));
                    }

                    foreach (String c in Templates)
                    {
                        sw.WriteLine(string.Format("<%@ Register Src=\"~" + Constants.TemplateUrlPath + "/{0}.ascx\" TagName=\"{0}\" TagPrefix=\"wet\" %>", c));
                    }

                    foreach (WeControl c in Controls)
                    {
                        string cssFile = "";
                        if (CopyStyleSheet(c, ref cssFile))
                        {
                            string linkfile = string.Format("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + Constants.TemplateUrlPath + "/styles/{0}\" media=\"screen\" />", cssFile);
                            if (HeadContent.IndexOf(cssFile) < 0)
                            {
                                HeadContent = HeadContent + "\r\n" + linkfile;
                            }
                        }
                    }

                    sw.WriteLine(HeadContent);
                    sw.Write(BodyContent);
                    sw.Flush();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 保存模板
        /// </summary>
        public void Save()
        {
            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            if (IsSubTemplate)
            {
                SaveSub();
            }
            else
            {
                using (FileStream fs = File.Open(FileName, FileMode.CreateNew, FileAccess.Write))
                {
                    using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
                    {
                        List <string> tags = new List <string>();
                        foreach (WeControl c in Controls)
                        {
                            if (!tags.Contains(c.TagName))
                            {
                                tags.Add(c.TagName);
                            }
                        }

                        sw.Write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n");

                        foreach (string c in tags)
                        {
                            sw.WriteLine(string.Format("<%@ Register Src=\"~" + Constants.ControlUrlPath + "/{0}.ascx\" TagName=\"{0}\" TagPrefix=\"wec\" %>", c));
                        }

                        foreach (String c in Templates)
                        {
                            sw.WriteLine(string.Format("<%@ Register Src=\"~" + Constants.TemplateUrlPath + "/{0}.ascx\" TagName=\"{0}\" TagPrefix=\"wet\" %>", c));
                        }

                        sw.Write("<html xmlns:wec=\"http://www.WestEngine.com\">\r\n");
                        sw.Write("<head runat=\"server\">\r\n");
                        //if(headContent.IndexOf("text/html; charset=UTF-8")<0)
                        //    sw.Write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\r\n");

                        HeadContent = FormatHeadMeta(HeadContent);
                        sw.Write("<title>");
                        sw.Write(Title);
                        sw.WriteLine("</title>");

                        foreach (WeControl c in Controls)
                        {
                            string cssFile = "";
                            if (CopyStyleSheet(c, ref cssFile))
                            {
                                string linkfile = string.Format("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + Constants.TemplateUrlPath + "/styles/{0}\" media=\"screen\" />", cssFile);
                                if (HeadContent.IndexOf(cssFile) < 0)
                                {
                                    HeadContent = HeadContent + "\r\n" + linkfile;
                                }
                            }
                        }

                        sw.Write(HeadContent);

                        sw.WriteLine("</head>");
                        sw.Write("<body");
                        sw.Write(BodyText);
                        sw.Write(">\r\n");
                        BodyContent = BodyContent.Replace("<#text />", "");
                        sw.Write(BodyContent);
                        sw.Write("</body>");
                        sw.Write("</html>");
                        sw.Flush();
                    }
                }
            }
        }