ZhiYeJianKang_PeiXun/Song.Extend/Html/HtmlInfo.cs
2025-02-20 15:41:53 +08:00

132 lines
4.0 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace Song.Extend.Html
{
public class HtmlInfo
{
private Context _Context;
public Context Context
{
get { return _Context; }
set { _Context = value; }
}
#region
public struct HtmlFileInfo
{
public string Name;
public string Path;
public string FullName;
}
public HtmlFileInfo File = new HtmlFileInfo();
#endregion
private HtmlInfo()
{
}
public HtmlInfo(string fullPath)
{
fullPath=System.Web.HttpContext.Current.Server.MapPath(fullPath);
System.IO.FileInfo fi = new FileInfo(fullPath);
this.File.FullName = fi.FullName;
this.File.Path = fi.Directory.FullName;
this.File.Name = fi.Name;
this._Context = new Context();
if (fi.Exists)
{
System.IO.StreamReader sr = new StreamReader(fullPath, System.Text.Encoding.UTF8);
this._Context.Text = sr.ReadToEnd();
sr.Close();
}
else
{
throw new System.NotImplementedException();
}
}
public HtmlInfo(string path, string file)
{
path = System.Web.HttpContext.Current.Server.MapPath(path);
System.IO.FileInfo fi = new FileInfo(path+"\\"+file);
this.File.FullName = fi.FullName;
this.File.Path = fi.Directory.FullName;
this.File.Name = fi.Name;
this._Context = new Context();
if (fi.Exists)
{
System.IO.StreamReader sr = new StreamReader(path + "\\" + file, System.Text.Encoding.UTF8);
this._Context.Text = sr.ReadToEnd();
sr.Close();
}
else
{
throw new System.NotImplementedException();
}
}
/// <summary>
/// 存储HTML数据1为成功0为失败
/// </summary>
/// <returns></returns>
public int Save()
{
System.IO.FileInfo fi = new FileInfo(this.File.FullName);
string attr = fi.Attributes.ToString();
if (attr.IndexOf("ReadOnly") < 0)
{
System.IO.StreamWriter sw = new StreamWriter(this.File.FullName, false, System.Text.Encoding.UTF8);
sw.Write(this._Context.Text);
sw.Close();
return 1;
}
else
{
return 0;
}
}
/// <summary>
/// 存储HTML数据将当前文件另存路径不变
/// </summary>
/// <returns>1为成功0为失败</returns>
public int Save(string file)
{
string fullpath = this.File.Path +"\\"+ file;
System.IO.FileInfo fi = new FileInfo(fullpath);
string attr = fi.Attributes.ToString();
if (attr.IndexOf("ReadOnly") < 0)
{
System.IO.StreamWriter sw = new StreamWriter(fullpath, false, System.Text.Encoding.UTF8);
sw.Write(this._Context.Text);
sw.Close();
return 1;
}
else
{
return 0;
}
}
public int Save(string path,string file)
{
string fullpath = path + file;
System.IO.FileInfo fi = new FileInfo(fullpath);
string attr = fi.Attributes.ToString();
if (attr.IndexOf("ReadOnly") < 0)
{
System.IO.StreamWriter sw = new StreamWriter(fullpath, false, System.Text.Encoding.UTF8);
sw.Write(this._Context.Text);
sw.Close();
return 1;
}
else
{
return 0;
}
}
}
}