如果没有生成当天的文件夹的时候,出现:
Set htmout = objfso.CreateTextFile(formpath&"\"&makefilename)
这行路径未找到。
如果已经存在这个文件夹的时候出现:
Set htmout = objfso.CreateTextFile(formpath&"\"&makefilename)
这行路径未找到。
我是个新手,正在学习中,请个位朋友帮忙指点一下,谢谢!
<%
function makefilename()
fname = now()
fname = replace(fname,"-","")
fname = replace(fname," ","")
fname = replace(fname,":","")
fname = replace(fname,"PM","")
fname = replace(fname,"AM","")
fname = replace(fname,"上午","")
fname = replace(fname,"下午","")
randomize
ranNum=int(90000*rnd)+10000 '生成随机数
fname = fname&fanNum
makefilename=fname & ".htm"
end function
if request("body")<>"" then
set objfso = Server.Createobject("Scripting.FileSystemobject") '创建一个fso实例
formPath=datepart("yyyy",now())&"_"&datepart("m",now())&"_"&datepart("d",now()) '建立目录名,生成的文件将按存放在此处
htmout = server.mappath(formpath& "/" &makefilename)
if objfso.folderexists(server.mappath(formPath)) then '如果该目录存在
Set htmout = objfso.CreateTextFile(formpath&"\"&makefilename)
else
objfso.createfolder(server.mappath(formPath)) '创建一个文件夹
Set htmout = objfso.CreateTextFile(formpath&"\"&makefilename)
htmout.write "<html><head><title>"
htmout.write request.form("title")
htmout.write "</title></head><body>新闻标题:"
htmout.write request.form("title")
htmout.write "<br>内容(body):"
htmout.write request.form("body")
htmout.write "</body></html>"
htmout.close
set htmout=nothing
set objfso=nothing
end if
end if
%>
<form name="form1" method="post" action="">
<table width="300" border="0" align="center">
<tr>
<td align="right">标题:</td>
<td colspan="2"><input name="title" size=18></td>
</tr>
<tr>
<td align="right">内容:</td>
<td colspan="2"><textarea name="body"></textarea></td>
</tr>
<tr>
<td align="right"> </td>
<td><input type="submit" name="Submit" value="生成"></td>
<td><a href="<%=makefilename%>" target="_blank">查看输出的文件</a></td>
</tr>
</table>
<br>
<br>
<br>
</form>
參考答案:if objfso.folderexists(server.mappath(formPath)) then '如果该目录存
objfso.createfolder(server.mappath(formPath)) '创建一个文件夹
这两行是对的
Set htmout = objfso.CreateTextFile(formpath&"\"&makefilename)
这行是错的,文件名也要用Server.MapPath来获得物理路径。