免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
ASP.NET實現(xiàn)新聞頁面的分頁功能[生成靜態(tài)版]

//生成靜態(tài)網(wǎng)頁

             string path = Server.MapPath("~/news/" + folder + "/");

             string file_template_name = Server.MapPath("~/news/template.htm");    //新聞模版文件
             string file_template_content = "";
             StreamReader sr_reader = new StreamReader(file_template_name, Encoding.GetEncoding("gb2312"));
             file_template_content = sr_reader.ReadToEnd();
             sr_reader.Close();
             string[] subContent = FileSplit(content);
             string file_content = "";
             int pageNum = 0;
             while (pageNum < 10 && subContent[pageNum] != "" && subContent[pageNum] != null)
                 pageNum++;
             for (int index = 0; index < pageNum; index++)
             ...{
                 file_content = file_template_content;
                 file_content = file_content.Replace("$$category", list_department.SelectedItem.Text);     //新聞類別
                 file_content = file_content.Replace("$$title", title);                //新聞標(biāo)題
                 file_content = file_content.Replace("<!--來源:$$author-->", "來源:" + author);         //作者
                 file_content = file_content.Replace("$$time", time);                      //添加時間
                 file_content = file_content.Replace("$$content", subContent[index]);        //新聞?wù)?br>                 string pageLink = "";
                 int firstPage = 0;
                //生成頁碼
                 if (index > 2) firstPage = index - 2;
                 for (int i1 = firstPage; i1 < index + 3 && i1 < pageNum; i1++)
                 ...{
                     if (i1 == index)
                         pageLink = pageLink + "[" + (index + 1) + "]" + "       ";
                     else pageLink = pageLink + "<a href=" + htmlfilename + i1 + ".htm>[" + (i1 + 1) + "]</a>       ";

                 }
                 if (index < pageNum - 1)
                     pageLink = pageLink + "<a href=" + htmlfilename + (index + 1) + ".htm>" + "下一頁" + "</a>       ";
                 if (index > 0)
                     pageLink = "<a href=" + htmlfilename + (index - 1) + ".htm>" + "上一頁" + "</a>       " + pageLink;
                 file_content = file_content.Replace("<!-- $$pageLink -->", pageLink);
                 if (index == pageNum - 1&&attachment_filename != null && attachment_filename != String.Empty)
                 ...{
                     string[] attachment = attachment_filename.Split(new char[] ...{ '|' });
                     string attachmenthtml = "<a href="attachment/" + attachment[0] + "" >" + attachment[0] + "</a>";
                     for (int j = 1; j < attachment.Length; j++)
                         attachmenthtml = attachmenthtml + "<br/>                <a href="attachment/" + attachment[j] + "" >" + attachment[j] + "</a>";
                     file_content = file_content.Replace("$$attachment", attachmenthtml);
                 }
                 StreamWriter sw = new StreamWriter(path + htmlfilename + index + ".htm", false, Encoding.GetEncoding("gb2312"));
                 sw.Write(file_content);
                 sw.Flush();
                 sw.Close();
             }
             HyperLink1.Text = "預(yù)覽: " + title;
             HyperLink1.NavigateUrl = "../news/" + folder + "/" + htmlfilename   + "0" + ".htm";
             HyperLink1.Visible = true;
             txt_time.Text = DateTime.Now.ToString("yyyy-MM-dd");
             txt_title.Text = "";
             txt_author.Text = "";
             FreeTextBox1.Text = "";
         }
         catch (Exception e)
         ...{
         }
     }
    
     //將正文分成多個頁面
protected string[] FileSplit(string fileContent)
     ...{
         int fileIndex = 0;
         string[] splitedFile = new string[10];
         while (fileContent.Length > 1500 && fileIndex < 9)     //每頁至少1500個字符
         ...{
             if (fileContent.IndexOf("<P>", 1500) < 0) break;
             splitedFile[fileIndex] = fileContent.Substring(0, fileContent.IndexOf("<P>", 1500));
             fileContent = fileContent.Remove(0, splitedFile[fileIndex].Length);
             fileIndex++;
         }
         splitedFile[fileIndex] = fileContent;    //超過9頁,剩下部分全放第十頁
         return splitedFile;
     }
}

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Tip:如何指定瀏覽器下載并保存動態(tài)生成的數(shù)據(jù)時對話框里的默認(rèn)文件名
JAVA讀寫文件,如何避免中文亂碼 - 52齋347 - JavaEye技術(shù)網(wǎng)站
Asp.net MVC處理文件的上傳下載
16. 文件的保存與讀取
android開發(fā)中的文件操作
pypdf Merging multiple pdf files into one pdf
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服