用文本+ASP打造新闻发布系统(四)新闻删除

2016-01-29 20:20 13 1 收藏

用文本+ASP打造新闻发布系统(四)新闻删除,用文本+ASP打造新闻发布系统(四)新闻删除

【 tulaoshi.com - ASP 】

<!--#include file="news_session.asp"--

<%
dim id
id=Request.QueryString ("id")
dim myfso
set myfso=createobject("scripting.filesystemobject")
if myfso.FileExists(server.mappath("./news_content/"&id&".txt"))then
myfso.DeleteFile (server.mappath("./news_content/"&id&".txt"))'#############删除新闻内容
end if

dim mytext2,myread2
set myread2=myfso.opentextfile(server.mappath("./new_list.asp"),1,0)
if myread2.atendofstream then
Response.Write "没有新闻内容"
myread2.close
Response.End
end if

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/asp/)

mytext2=myread2.readall
myread2.close
dim listarray,i,h,count,sf,title
listarray=split(mytext2,"|") '#########读取记录并以#分割成listarray数组
count=ubound(listarray)
for i=0 to count '###########根据ID找到该新闻实现删除功能
sf=split(listarray(i),",")
if right(sf(0),7)=right(id,7) then
dim thisid
thisid=i

'#######为6说明上传了图片,删除新闻图片和该列表记录
if ubound(sf)=6 then
myfso.deletefile(server.MapPath ("./images/"&sf(6)))
end if
exit for
end if
next

dim mytext,mappath
mappath=server.mappath("./")
set mytext=myfso.createtextfile(mappath&"new_list.asp",-1,0)
for i=0 to thisid-1' ##########把所有数据重新写入文件
mytext.write listarray(i)&"|"
next

for i=thisid+1 to ubound(listarray)
if i=ubound(listarray) then
mytext.write listarray(i)
exit for
else
mytext.write listarray(i)&"|"
end if
next
mytext.close
%
<script language="javascript"
alert("删除成功");
location.href =("news_admin1.asp");
---------------
news_view.asp
<% Response.Expires=0
dim myid,myfso,myread,mytext1
myid=request.querystring("id")

if len(myid)=0 then
Response.Write "没有该新闻"
Response.End
end if

set myfso=createobject("scripting.filesystemobject")
set myread=myfso.opentextfile(server.mappath("./news_content/"&myid&".txt"),1,0)
if myread.atendofstream then
Response.Write "没有新闻内容"
Response.End
else
mytext1=myread.readall '#######打开对应的新闻内容文件,并读取用变量存储


function htmlencode2(str)'###########字符处理函数
dim result
dim l
l=len(str)
result=""
dim i
for i = 1 to l
select case mid(str,i,1)
case chr(34)
result=result+""""
case "&"
result=result+"&"
case chr(13)
result=result+"<br"
case " "
result=result+" "
case chr(9)
result=result+" "
case chr(32)
result=result+" "
if i+1<=l and i-10 then
if mid(str,i+1,1)=chr(32) or mid(str,i+1,1)=chr(9) or mid(str,i-1,1)=chr(32) or mid(str,i-1,1)=chr(9) then
result=result+" "
else
result=result+" "
end if
else
result=result+" "
end if
case else
result=result+mid(str,i,1)
end select
next
htmlencode2=result
end function



myread.close
end if

dim mytext2,myread2
set myread2=myfso.opentextfile(server.mappath("./new_list.asp"),1,0)

if myread2.atendofstream then
Response.Write "没有新闻内容"
Response.End
else
mytext2=myread2.readall
myread2.close
dim listarray,i,h
listarray=split(mytext2,"|") '#########读取记录并以#分割成listarray数组

dim count,sf,title,src
count=ubound(listarray)

for i=0 to count '###########根据ID找到该新闻并把文章点击次数加1
sf=split(listarray(i),",")
if right(sf(0),7)=right(myid,7) then
title=sf(1)
src="https://img.tulaoshi.com/attachment/portal","&sf(1)&","&sf(2)&","&sf(3)&","&sf(4)&","&sf(5)&","&sf(6)
dim mypic
mypic=sf(6)
else
listarray(i)=sf(0)&","&sf(1)&","&sf(2)&","&sf(3)&","&sf(4)&","&sf(5)
end if
'##################
exit for
end if

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/asp/)

next

dim k,mytext,mappath
mappath=server.mappath("./")
set mytext=myfso.createtextfile(mappath&"new_list.asp",-1,0)<

来源:https://www.tulaoshi.com/n/20160129/1511031.html

延伸阅读
标签: ASP
  紧接上节,我们的新闻系统已能完成日常的新闻在线添加,删除等的功能,但这 还是不足够的,有的用户可能需要查找一下过往某一专题内容的相关新闻条目,而一 个比教完善的新闻系统,当然少不免也的完成这个功能。    现在马上就为我们的新闻系统添加上(全文/标题)的检索功能吧,首先我们做 一个检索表单,见下面的...
标签: ASP
  通过定制这段代码,就能制作出符合您要求的网页显示格式。    添加,删除,显示都讲解完了,最后一项,就是把新闻的详细内容显示出来。    当用户点击新闻标题,就打开disp.asp文件,同时使用GET这种方式来把参数传 递过去,我们看看disp.asp的文件内容       《% @lan...
标签: ASP
  更新每天新闻内容,对webmaster们来说是一件很头痛的事,首先,收集了大量 的新闻资料后,还必须制作大量的网页,每天大大小小的国际新闻,国内新闻,IT 新闻,可真够你累的。最致命的一点,这些松散的新闻是管理不了的,不能查询,不 能在线动态删改,新闻讲求时效性,当你作好网页然后上传到服务器上的时侯,恐怕 别人已早你一步,...
标签: ASP
  (一)构建新闻数据库    分析一下构成每条新闻的元素,主要由新闻标题,新闻内容,图片地址,连接地 址,新闻的发布时间组成。而在构建数据库的时候。考虑到处理需要,必需加上新闻 的ID号,以便识别。再者的话,可以加上点击统计,以便了解读者感性趣的内容。 access数据库是一个非常适合于开发阶段使用的过度时...
标签: ASP
  (二)添加和管理每天的新闻内容    当进行了新闻提交后,则交由一个名为addnew.asp的asp程序来对新闻内容进行 处理,以便分类和保存,为了显示清析,我们每提交一条新闻,下面的那个新闻内容 库就重新读入,以便可以查看新闻是否能成功加入都数据库中,也可以放便地删除新 闻内容。     现在看...

经验教程

427

收藏

57
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部