您好,登錄后才能下訂單哦!
html: <input id="Fi_Fp" runat="server" name="Fi_Fp" type="file" />
.cs:
using System.IO;
using System.Text.RegularExpressions;
using System.Windows.Forms;
if (Fi_Fp.PostedFile.ContentLength > 0)//上傳了新圖書
{
b._upfile = uploadFile(Fi_Fp);
if (isTxt == true)
{ b._txtlist = readtxtmm(b._upfile); }//重新提取目錄
}
public string uploadFile(HtmlInputFile File1)
{
Comm nadd = new Comm();
if (File1.PostedFile.ContentLength > 0)
{
string filenamec = null;
string fn = File1.PostedFile.FileName;
filenamec = "File_" + nadd.getRandomFilename();
filenamec += fn.Substring(fn.LastIndexOf("."));
string ext = fn.Substring(fn.LastIndexOf(".") + 1).ToLower();
if (ext == "txt") { isTxt = true; }
if (SET(ext))
{
string Picpath = System.Configuration.ConfigurationManager.AppSettings["bookfile"].ToString().Trim();
File1.PostedFile.SaveAs(HttpContext.Current.Server.MapPath(Picpath) + filenamec);
deleteoldfile(Server.MapPath("../bookfile/") + Session["upfile"]);//刪除舊文件
return filenamec;
}
else
{
return "格式不正確!";
}
}
else
{
return "";
}
}
public void deleteoldfile(string oldfile)
{
//判斷文件是不是存在
if (File.Exists(@""+oldfile+""))
{
//如果存在則刪除
File.Delete(@"" + oldfile + "");
}
}
public bool SET(string extion)
{
string[] extAry =
{"txt","doc","ppt","jpg","pdf","bmp","docx"
};
for (int i = 0; i < extAry.Length; i++)
{
if (extAry[i] == extion)
{
return true;
}
}
return false;
}
//提取章節名及開始行號結束行號
public string readtxtmm(string url)//url txt文件路徑
{
string path = Server.MapPath("../bookfile/") + url;
string str = "第(?<value>[\\w]*?)章";//查找章節關鍵字 *號為變量
string wz = ""; //章節及行號列表
string[] stringlines = File.ReadAllLines(path, System.Text.Encoding.Default);
Regex reg = new Regex(str);
for (int i = 0; i < stringlines.Length; i++)
{
Match mat = reg.Match(stringlines[i].ToString());
if (mat.Success)
{
if (i != 0)
{
wz += "," + (i - 1) + "|" + i + "," + stringlines[i].ToString();//上一章結尾行號,本章開始行號 章節名
}
else
{ wz += "0," + stringlines[i].ToString(); }
}
}
wz += "," + stringlines.Length + "|";
return wz;
}
//讀取目錄沒人并輸出
//讀取章節內容
string path = Server.MapPath("bookfile/") + url;
string[] stringlines = File.ReadAllLines(path, System.Text.Encoding.Default);
booktitle = stringlines[start].ToString();
for (int i = start+1; i <= end; i++)
{
if (i < stringlines.Length)
{
if ( stringlines[i].ToString().Trim().Length>0)
{
bookscontent.Text += "<p>" + stringlines[i].ToString() + "</p>";
}
}
}
//讀取上一頁下一頁
string[] list = txtlist.Split('|');
for (int i = 0; i < list.Length; i++)
{
if (list[i].ToString().Trim() != "")
{
string[] dang = list[i].Split(',');
if (int.Parse(dang[0].ToString()) == start)
{
if (i - 1 >= 0)
{
string[] arrlist = list[i - 1].Split(',');
uppage = "上一頁:<a href=\"WorkerStudyView.aspx?BLid=" + blid + "&start=" + arrlist[0].ToString() + "&end=" + arrlist[2].ToString() + "\">" + arrlist[1].ToString().Trim() + "</a><br />";
}
if (i + 1 < list.Length-1)
{
string[] arrlist = list[i + 1].Split(',');
nextpage = "下一頁:<a href=\"WorkerStudyView.aspx?BLid=" + blid + "&start=" + arrlist[0].ToString() + "&end=" + arrlist[2].ToString() + "\">" + arrlist[1].ToString().Trim() + "</a><br />";
}
break;
}
}
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。