Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 31st, 2003, 08:13 PM
Authorized User
 
Join Date: Jun 2003
Location: Sheridan, OR, USA.
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

%>
Reply With Quote
  #2 (permalink)  
Old August 1st, 2003, 12:12 AM
Authorized User
 
Join Date: Jul 2003
Location: Athens, , Greece.
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Your administrator should think again, because it is a permissions problem. I had the same problem when i was trying to delete files through ASP. You have to add IUSR and IWAM to the permitted users and give IUSR "modify" rights.Some would say that giving your Internet users access to delete files is not safe, but its the only way..

Cheers
Kostas Lagos

Reply With Quote
  #3 (permalink)  
Old August 15th, 2003, 11:17 AM
Authorized User
 
Join Date: Jun 2003
Location: Sheridan, OR, USA.
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Kostas:

Thank you very much for the response.

I apologize for the delay in responding to you. The sys admin has been out of town for a week and the issue has been on the back burner until his return. I lost track of the fact that I had left a post on this forum.

I want you to know I appreciate the information and your help.

JK
Reply With Quote
  #4 (permalink)  
Old August 17th, 2003, 06:53 PM
Authorized User
 
Join Date: Jun 2003
Location: Quezon City, MM, Philippines.
Posts: 97
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to planeswalk
Default

Hi,

Try choosig another folder to create and delete your files in. Just remember that you need to have Modify permissions on a folder for you to delete files, and not only Write permissions. If you choose to work on a folder that is inside your web file folder tree, then your administrator should have no problems with it.

Cheers!


Marlon Villarama
Support Team
Web Burner Hosting
marlon@webburner.com
www.webburner.com
Toll-Free: 877-535-2876
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't delete a file with the FileSystemObject Berni016x Classic ASP Components 4 August 30th, 2013 04:41 AM
How Can I Delete Cookie files. MICZ VB How-To 4 August 18th, 2007 04:56 AM
Read Files from Folder using "FileSystemObject" davekrunal46 VB How-To 1 December 10th, 2005 07:43 AM
delete files in the server miguel.ossa Classic ASP Basics 1 September 5th, 2005 12:15 PM
Delete Files qazi_nomi Classic ASP Basics 7 October 18th, 2004 06:55 PM



All times are GMT -4. The time now is 01:04 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.