根据html页面模板动态生成html页面(c#类)_c#应…
2008-02-23 05:43:33来源:互联网 阅读 ()
114 /// 编码
115 ///
116 public Encoding Code
117 {
118 get{ return this._code;}
119 set{ this._code=Encoding.GetEncoding(value.ToString());}
120 }
121 /**
122 /// 错误文档所在路径
123 ///
124 public string ErrLogPath
125 {
126 get{
127 if(!(this._errlogPath==null))
128 return this._errlogPath;
129 else
130 return "aspxTohtml_log.txt";
131 }
132 set{this._errlogPath=value;}
133 }
134
135
136 #endregion
137
138 操作#region 操作
139
140 /**
141 /// 获取转换后的html文档所在相对文档路径
142 /// 如:假如HtmlFilePath="/news/"
143 /// 转换后的html文档名为200505050505.html
144 /// 则返回的值为/news/200505050505.html
145 ///
146 /// 假如在未调用StartConvert方法之前调用此属性则返回null
147 public string HtmlFileVirtualPath
148 {
149 get
150 {
151 if(!(this._convertedFilename==""))
152 return this.HtmlFilePath this._convertedFilename;
153 else
154 return null;
155 }
156 }
157
158 /**
159 /// 为HTML页面参数数组付值
160 ///
161 ///
162 public void setTemplateFileparameter(string[] param)
163 {
164 try
165 {
166 if(param.Length==this.TemplateParamCount)
167 this._templateFileparameter=param;
168 //else//和原定义的个数不等
169 //
170 }
171 catch(System.Exception ex)
172 {
173 WriteErrFile(ex);
174 }
175 }
176 /**
177 /// 为aspx文档中将要替换html文档中的参数数组付值
178 ///
179 ///
180 public void setAspxFileparameter(string[] param)
181 {
182 try
183 {
184 if(param.Length==this.TemplateParamCount)
185 this._aspxFileparameter=param;
186 //else//和原定义的个数不等
187 //
188 }
189 catch(System.Exception ex)
190 {
191 WriteErrFile(ex);
192 }
193 }
194 /**
195 /// 开始进行aspxTohtml转换
196 ///
197 /// 返回值为成功创建后的文档名称
198 /// 在调用此方法之前必需确定已调用setTemplateFileparameter 和setAspxFileparameter方法进行相应的付值操作
199 public string StartConvert()
200 {
201 if(this._templateFileparameter.Length==this._aspxFileparameter.Length)
202 {
203 return writeFile();
204 }
205 else{
206 return null;
207 }
208 }
209 /**
210 /// 开始进行aspxTohtml转换
211 ///
212 /// html模板页中的任何参数数组
213 /// aspx页面中要代替html模板页中参数值数组
214 /// 返回值为成功创建后的文档名称
215 public string StartConvert(string[] htmlparam,string[] aspxparam)
216 {
217 //先调用setTemplateFileparameter 和setAspxFileparameter方法,进行付值操作
218 setTemplateFileparameter(htmlparam);
219 setAspxFileparameter(aspxparam);
220 //
221 string fn=this.StartConvert();
222 //
223 _convertedFilename=fn;
224 //
225 return fn;
226 }
227
228 /**
229 /// 用时间加随机数生成一个文档名
230 ///
231 ///
232 private string getfilename()
233 {
234 //用时间加随机数生成一个文档名
235 System.Threading.Thread.Sleep(50);
236 string yearStr = System.DateTime.Now.Year.ToString();
237 string monthStr = string.Format("{0:0#}",System.DateTime.Now.Month);
238 string dayStr = string.Format("{0:0#}",System.DateTime.Now.Day);
239 string hourStr = string.Format("{0:0#}",System.DateTime.Now.Hour);
240 string minuteStr = string.Format("{0:0#}",System.DateTime.Now.Minute);
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
相关文章