一个asp问题

王朝知道·作者佚名  2010-02-24
窄屏简体版  字體: |||超大  
 
分類: 電腦/網絡 >> 程序設計 >> 其他編程語言
 
問題描述:

我做了个新闻系统,使用静态生成html文件技术

但是生成过程中老是出错(在本地调试好用)

一放到服务器上就是创建文件失败

下面是关键代码

'**************************************************

'函数名:AutoCreateFolder

'作 用:自动创建指定的多级文件夹。

'参 数:strPath :文件夹绝对路径

'返回值:True,False

'**************************************************

Function AutoCreateFolder(strPath) ' As Boolean

On Error Resume Next

Dim astrPath, ulngPath, i, strTmpPath

Dim objFSO

If InStr(strPath, "\") <=0 Or InStr(strPath, ":") <= 0 Then

AutoCreateFolder = False

Exit Function

End If

Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

If objFSO.FolderExists(strPath) Then

AutoCreateFolder = True

Exit Function

End If

astrPath = Split(strPath, "\")

ulngPath = UBound(astrPath)

strTmpPath = ""

For i = 0 To ulngPath

strTmpPath = strTmpPath & astrPath(i) & "\"

If Not objFSO.FolderExists(strTmpPath) Then

' 创建

objFSO.CreateFolder(strTmpPath)

End If

Next

Set objFSO = Nothing

If Err = 0 Then

AutoCreateFolder = True

Else

AutoCreateFolder = False

End If

End Function

'**************************************************

'函数名:CreateFile

'作 用:创建文件。

'参 数:FilePath:文件路径,FileName:文件名,FileBody:文件内容

'返回值:无

'**************************************************

Function CreateFile(FilePath,FileName,FileBody)

Set fso = Server.CreateObject("Scripting.FileSystemObject")

'调用AutoCreateFolder函数创建目录

if not fso.FolderExists(server.Mappath(FilePath)) then AutoCreateFolder(server.mappath(FilePath))

'使用FSO对象创建文件

Set fwrite = fso.CreateTextFile(server.mappath(FilePath&"\"&FileName))

fwrite.WriteLine FileBody

fwrite.close

set fso=nothing

End Function

问题就是出在“if not fso.FolderExists(server.Mappath(FilePath)) then AutoCreateFolder(server.mappath(FilePath))

'使用FSO对象创建文件

Set fwrite = fso.CreateTextFile(server.mappath(FilePath&"\"&FileName))”

代码段,“

Set fwrite = fso.CreateTextFile(server.mappath(FilePath&"\"&FileName))””根本不执行(我用response跟踪的)

我又使用response.write(fso.FolderExists(server.Mappath(FilePath)) )

response.end

来判断true 或者false 但是根本没执行 好象直接跳过去了

不知道为什么?

谢谢大家指教!!!

參考答案:

我对这方面并不是非常了解,但是给个建议吧……

看看您的远程装载ASP脚本的文件夹属性设置,要通过语言创建文件,基文件夹必须是可读可写的。

再有,确认一下远程主机是否可以使用FSO,有的ASP主机会禁用FSO防止病毒。请稍微注意一下。

小贴士:① 若网友所发内容与教科书相悖,请以教科书为准;② 若网友所发内容与科学常识、官方权威机构相悖,请以后者为准;③ 若网友所发内容不正确或者违背公序良俗,右下举报/纠错。
 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航