|
Subject:
|
question to chinese encoding
|
|
Posted By:
|
yingmingming
|
Post Date:
|
10/8/2004 2:33:43 AM
|
First:I use EditFile.aspx to edit SiteFooter.ascx. I click Save_Click Button to save SiteFooter.ascx after add chinese words. Second:Footer of web display chaos encoding when I visit web
|
|
Reply By:
|
bmains
|
Reply Date:
|
10/8/2004 4:58:46 PM
|
Does the browser have all the right language packs, and what was your specific error?
|
|
Reply By:
|
yingmingming
|
Reply Date:
|
10/8/2004 7:48:13 PM
|
My answer: EditFile.aspx.cs: using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.IO;
namespace Wrox.WebModules.FileManager.Web { public class EditFile : System.Web.UI.Page { protected System.Web.UI.WebControls.Label StatusMessage; protected System.Web.UI.WebControls.TextBox SaveAsPath; protected System.Web.UI.WebControls.TextBox FileContent; protected System.Web.UI.WebControls.Button Save; protected System.Web.UI.WebControls.Table Table1; protected System.Web.UI.WebControls.Button Back;
private void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string filePath = Request.Params["File"]; if (filePath != null) { if (Request.Params["CreateFile"] == null || Request.Params["CreateFile"]=="false") {
try { StreamReader sr = new StreamReader (File.Open(Server.MapPath(filePath), FileMode.Open),System.Text.Encoding.GetEncoding("gb2312")); FileContent.Text = sr.ReadToEnd(); sr.Close(); } catch (Exception exc) { StatusMessage.Text = exc.Message; StatusMessage.Visible = true; } } SaveAsPath.Text = filePath; } } } protected void Back_Click(object sender, EventArgs e) { string filePath = Request.Params["File"]; if (filePath != null && filePath != "/") { int lastSlashIndex = filePath.LastIndexOf("/"); string folderPath = filePath.Substring(0, lastSlashIndex+1); Response.Redirect("BrowseFiles.aspx?Folder=" + folderPath); } else Response.Redirect("BrowseFiles.aspx"); }
protected void Save_Click(object sender, EventArgs e) { try { string filePath = SaveAsPath.Text; if (!filePath.StartsWith("/")) filePath = "/" + filePath; StreamWriter sw = new StreamWriter(Server.MapPath(filePath),false,System.Text.Encoding.GetEncoding("gb2312")); sw.Write(FileContent.Text); sw.Close(); StatusMessage.Text = "Îļþ³É¹¦±£´æ"; } catch (Exception exc) { StatusMessage.Text = exc.Message;; } StatusMessage.Visible = true; }
#region Web Form Designer generated code override protected void OnInit(EventArgs e) {
base.OnInit(e); InitializeComponent(); } private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load);
} #endregion } }
|