Using text +asp to build press release system (iv) News deletion

Source: Internet
Author: User
Tags arrays exit chr count split
<!--#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 "No news content"
Myread2.close
Response.End
End If

Mytext2=myread2.readall
Myread2.close
Dim listarray,i,h,count,sf,title
Listarray=split (mytext2, "|") ' ######## #读取记录并以 # split into Listarray arrays
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说明上传了图片, delete the news picture and the list record
If UBound (SF) =6 Then
Myfso.deletefile (server. MapPath ("./images/" &AMP;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 ("Delete succeeded");
Location.href = ("news_admin1.asp");
</script>
---------------
News_view.asp
<% response.expires=0
Dim myid,myfso,myread,mytext1
Myid=request.querystring ("id")

If Len (myID) =0 Then
Response.Write "No Such news"
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 "No news content"
Response.End
Else
Mytext1=myread.readall ' ###### #打开对应的新闻内容文件, and read with variable storage


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-1>0 then
If Mid (str,i+1,1) =CHR or mid (str,i+1,1) =CHR (9) or mid (str,i-1,1) =CHR (?) 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 "No news content"
Response.End
Else
Mytext2=myread2.readall
Myread2.close
Dim listarray,i,h
Listarray=split (mytext2, "|") ' ######## #读取记录并以 # split into Listarray arrays

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=SF (3)
SF (4) =SF (4) +1

' ###### #为6说明上传了图片, stored as a new array
If UBound (SF) =6 Then
Listarray (i) =sf (0) & "," &AMP;SF (1) & "," &AMP;SF (2) & "," &AMP;SF (3) & "," &AMP;SF (4) & "," &AMP;SF (5) & "," &AMP;SF (6)
Dim mypic
MYPIC=SF (6)
Else
Listarray (i) =sf (0) & "," &AMP;SF (1) & "," &AMP;SF (2) & "," &AMP;SF (3) & "," &AMP;SF (4) & "," &AMP;SF (5)
End If
'##################
Exit For
End If

Next

Dim k,m



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.