一个本地好的,服务器上坏的的问题.
1. 从 资源url 读取内容,再对内容进行分析组合成一个 strWant;
2. 读取 模板 内容.
3. 用准备好的 strwant 取代 模板中的指定内容.并将取代后的模板写入输出文件.
-------------------------------------
代码如下:
参数: OutFileStr = "../analysis/outfile.htm ";
InUrlStr = "http://community.csdn.net/Expert/PostNew.asp?room=5202 ";
-------------------------------------
private void BuildAnalysis(string OutFileStr, string InUrlStr)
{
WebRequest myWebRequest = WebRequest.Create(InUrlStr);
WebResponse myWebResponse = myWebRequest.GetResponse();
Stream ReceiveStream = myWebResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding( "gb2312 ");
StreamReader readStream = new StreamReader( ReceiveStream, encode );
// "../Analysis/AnalysisArticleTpl.htm " 是模板文件
FileStream fsForTemplate = new FileStream(Server.MapPath( "../Analysis/AnalysisArticleTpl.htm "), FileMode.Open, FileAccess.Read);
StreamReader srForTemplate = new StreamReader(fsForTemplate, encode);
string strTemplate = srForTemplate.ReadToEnd();
Char[] read = new Char[256];
int count = readStream.Read( read, 0, 256 );
StringBuilder strhtml = new StringBuilder( " ");
while (count > 0)
{
String str = new String(read, 0, count);
strhtml.Append(str);
count = readStream.Read(read, 0, 256);
}
readStream.Close();
srForTemplate.Close();
fsForTemplate.Close();
// Rsplay(stringbuilder) 是一个分析组合方法
Rsplay(strhtml);
FileStream fs = new FileStream(Server.MapPath(OutUrlStr), FileMode.Create, FileAccess.Write);
StreamWriter writeStream = new StreamWriter(fs, encode);
// MessageBox_Open(string) 用来弹出进行到的步骤,在这里,本地可以弹,服务器上不能弹出
// 模板,资源url试过了,可以读可以弹.
this.MessageBox_Open(Server.MapPath(OutUrlStr));
strTemplate = strTemplate.Replace( "{AnalysisArticle} ", strhtml.ToString());
writeStream.Write(strTemplate);
writeStream.Close();
myWebResponse.Close();
}
------解决方案--------------------OutFileStr在方法里没直接用,是不是和这个路径有关,查下