Create/Delete files w/ASP using FileSystemObject
Hi:
I'm trying to create and delete text files from an ASP page. In the big picture, I want to run an executable against a created text file (the input file), that executable creates an output text file, I'll capture the content of the output file, and delete both text files.
I can create a file successfully. For now, I'm using the web server's TEMP directory and creating a temporary file name using methods of the FileSystemObject. However I cannot delete it. Permission denied.
Microsoft VBScript runtime error '800a0046'
Permission denied
The system admin doesn't think it is a permissions problem.
Any ideas are appreciated. I've included a sample page below. Nothing special about it. Should be able to slap it into the body of an ASP page and go.
Thanks,
JK
<%
Call CreateDeleteFile
%>
<%
Sub CreateDeleteFile
Dim fsoLocal
Dim txtstrmLocal
Dim strTempFileName
Set fsoLocal = Server.CreateObject("Scripting.FileSystemObject")
strTempFileName = fsoLocal.GetSpecialFolder(2) & "\" & fsoLocal.GetTempName
Response.Write "Generate temporary file name of '" & strTempFileName& "'<BR>"
Response.Write "Creating text file '" & strTempFileName & "'<BR>"
Set txtstrmLocal = fsoLocal.CreateTextFile(strTempFileName, False, False)
Response.Write "Writing to text file '" & strTempFileName & "'<BR>"
txtstrmLocal.Write ("this is a test sentence")
Response.Write "Closing text file '" & strTempFileName & "'<BR>"
txtstrmLocal.Close
Dim strTest
Response.Write "Opening text file '" & strTempFileName & "'<BR>"
Set txtstrmLocal = fsoLocal.OpenTextFile(strTempFileName, 1, 0)
Response.Write "Reading in content of text file '" & strTempFileName& "'<BR>"
strTest = txtstrmLocal.ReadAll
Response.Write "Closing text file '" & strTempFileName & "'<BR>"
txtstrmLocal.Close
Response.Write "Here is the output:<BR><BR>'" & strTest & "'<BR><BR>"
If fsoLocal.FileExists(strTempFileName) Then
Call DetermineFileAttributes(strTempFileName)
Response.Write "<BR>"
Response.Write strTempFileName & " exists, will attempt to delete...<BR>"
fsoLocal.DeleteFile strTempFileName, True
Else
Response.Write strTempFileName & " no longer exists.<BR>"
End If
Set fsoLocal = Nothing
End Sub
%>
<%
Sub DetermineFileAttributes(strTempFileName)
Dim fsoLocal
Dim filLocal
Dim intFileAttributes
Response.Write "HTTP_HOST = " & Request.ServerVariables("HTTP_HOST") & "<BR>"
Response.Write "APPL_PHYSICAL_PATH = " & Request.ServerVariables("APPL_PHYSICAL_PATH") & "<BR>"
Response.Write "HTTP_HOST = " & Request.ServerVariables("HTTP_HOST") & "<BR>"
Response.Write "LOGON_USER = " & Request.ServerVariables("LOGON_USER") & "<BR>"
Response.Write "REMOTE_USER = " & Request.ServerVariables("REMOTE_USER") & "<BR>"
Response.Write "AUTH_USER = " & Request.ServerVariables("AUTH_USER") & "<BR>"
Response.Write "LOCAL_ADDR = " & Request.ServerVariables("LOCAL_ADDR") & "<BR>"
Response.Write "<BR>"
Set fsoLocal = Server.CreateObject("Scripting.FileSystemObject")
If fsoLocal.FileExists(strTempFileName) Then
Response.Write strTempFileName & " exists, checking attributes...<BR>"
Set filLocal = fsoLocal.GetFile(strTempFileName)
Else
Response.Write strTempFileName & " no longer exists.<BR>"
End If
intFileAttributes = filLocal.Attributes
Response.Write "File Attribute return value: " & CStr(intFileAttributes) & "<BR><BR>"
Response.Write "Identifying attributes of the file: <BR>"
If intFileAttributes AND 1 Then
Response.Write "Read only<BR>"
Else
Response.Write "Not read only<BR>"
End If
If intFileAttributes AND 2 Then
Response.Write "Hidden<BR>"
Else
Response.Write "Not hidden<BR>"
End If
If intFileAttributes AND 4 Then
Response.Write "System<BR>"
Else
Response.Write "Not system<BR>"
End If
If intFileAttributes AND 8 Then
Response.Write "Volume<BR>"
Else
Response.Write "Not volume<BR>"
End If
If intFileAttributes AND 16 Then
Response.Write "Directory<BR>"
Else
Response.Write "Not directory<BR>"
End If
If intFileAttributes AND 32 Then
Response.Write "Archive<BR>"
Else
Response.Write "Not archive<BR>"
End If
If intFileAttributes AND 1024 Then
Response.Write "Alias<BR>"
Else
Response.Write "Not alias<BR>"
End If
If intFileAttributes AND 2048 Then
Response.Write "Compressed<BR>"
Else
Response.Write "Not compressed<BR>"
End If
Set filLocal = Nothing
Set fsoLocal = Nothing
End Sub
%>
|