| Author |
Deleting a File with ASP?
|
|
|
| Is it possible to use ASP to delete a file on the web server?
I have a form that allows users to submit files to my site, but I now want
them to be able to delete their files too if possible.
I know the location and filename of the files (this is taken from a
recordset).
I am not 100% adept in ASP (I am using Dreamweaver to make my site) so an
example would be good please.
Thanks
| |
| Christopher Brandsdal 2004-07-28, 3:55 pm |
| Here is a code example:
Dim objFSO
Dim objDelFile
Dim strFilePath
strFilePath= "filepath"
on error resume next
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objDelFile = objFSO.GetFile(Server.MapPath(strFilePath))
objDelFile.Delete
Set objDelFile = nothing
Set objFSO = nothing
"Keith" <@.> wrote in message news:#6j93AIdEHA.596@TK2MSFTNGP11.phx.gbl...
> Is it possible to use ASP to delete a file on the web server?
>
> I have a form that allows users to submit files to my site, but I now want
> them to be able to delete their files too if possible.
>
> I know the location and filename of the files (this is taken from a
> recordset).
>
> I am not 100% adept in ASP (I am using Dreamweaver to make my site) so an
> example would be good please.
>
> Thanks
>
>
| |
|
| Thanks
How can I make it use the following as the filepath/name? I am not familiar
enough to modify the code sample.
"../../../sections/policies/files/policies/" &
RS_Remove_Policy.Fields.Item("Policy_Category") & "/" &
RS_Remove_Policy.Fields.Item("Policy_File_Name")
When I use this in a Response.Write it displays the correct path and
filename so I know this bit works, just not sure how to put it in the code
sample - I always get with " and '
"Christopher Brandsdal" <brandsdal@binaer.no> wrote in message
news:u5qh$NIdEHA.1692@tk2msftngp13.phx.gbl...
> Here is a code example:
>
> Dim objFSO
> Dim objDelFile
> Dim strFilePath
> strFilePath= "filepath"
>
> on error resume next
> Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
> Set objDelFile = objFSO.GetFile(Server.MapPath(strFilePath))
> objDelFile.Delete
>
> Set objDelFile = nothing
> Set objFSO = nothing
>
>
>
> "Keith" <@.> wrote in message news:#6j93AIdEHA.596@TK2MSFTNGP11.phx.gbl...
want[color=darkred]
an[color=darkred]
>
>
| |
| Christopher Brandsdal 2004-07-28, 3:55 pm |
| Try this..
If it doesen't work, then just change the strFilePath....
Just to test that the string is valid, insert the followingtag, run the
code, and se if the result is the same as the actual path:
<%=Server.MapPath("../../../sections/policies/files/policies/" &
RS_Remove_Policy.Fields.Item("Policy_Category") & "/" &
RS_Remove_Policy.Fields.Item("Policy_File_Name"))%>
Here is the code withe the string you provided! Try this:
Dim objFSO
Dim objDelFile
Dim strFilePath
strFilePath= "../../../sections/policies/files/policies/" &
RS_Remove_Policy.Fields.Item("Policy_Category") & "/" &
RS_Remove_Policy.Fields.Item("Policy_File_Name")
on error resume next
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objDelFile = objFSO.GetFile(Server.MapPath(strFilePath))
objDelFile.Delete
Set objDelFile = nothing
Set objFSO = nothing
"Keith" <@.> wrote in message news:urAqxgIdEHA.2664@TK2MSFTNGP09.phx.gbl...
> Thanks
>
> How can I make it use the following as the filepath/name? I am not
familiar
> enough to modify the code sample.
>
> "../../../sections/policies/files/policies/" &
> RS_Remove_Policy.Fields.Item("Policy_Category") & "/" &
> RS_Remove_Policy.Fields.Item("Policy_File_Name")
>
> When I use this in a Response.Write it displays the correct path and
> filename so I know this bit works, just not sure how to put it in the code
> sample - I always get with " and '
>
>
> "Christopher Brandsdal" <brandsdal@binaer.no> wrote in message
> news:u5qh$NIdEHA.1692@tk2msftngp13.phx.gbl...
news:#6j93AIdEHA.596@TK2MSFTNGP11.phx.gbl...[color=darkred]
> want
> an
>
>
| |
| Tim Slattery 2004-07-28, 3:55 pm |
| "Keith" <@.> wrote:
>Is it possible to use ASP to delete a file on the web server?
>
>I have a form that allows users to submit files to my site, but I now want
>them to be able to delete their files too if possible.
>
>I know the location and filename of the files (this is taken from a
>recordset).
Not totally clear just what you're trying to do. You can use the
FileSystemObject to delete files on the server. You cannot delete
files on the client side.
--
Tim Slattery
MS MVP(DTS)
Slattery_T@bls.gov
| |
| Aaron [SQL Server MVP] 2004-07-28, 3:55 pm |
| http://www.aspfaq.com/2039
--
http://www.aspfaq.com/
(Reverse address to reply.)
"Keith" <@.> wrote in message news:#6j93AIdEHA.596@TK2MSFTNGP11.phx.gbl...
> Is it possible to use ASP to delete a file on the web server?
>
> I have a form that allows users to submit files to my site, but I now want
> them to be able to delete their files too if possible.
>
> I know the location and filename of the files (this is taken from a
> recordset).
>
> I am not 100% adept in ASP (I am using Dreamweaver to make my site) so an
> example would be good please.
>
> Thanks
>
>
| |
| Christopher Brandsdal 2004-07-28, 3:55 pm |
| By the way nice servername Aaron; MacGyver ;)
"Aaron [SQL Server MVP]" <ten.xoc@dnartreb.noraa> wrote in message
news:u0To3lKdEHA.1764@TK2MSFTNGP10.phx.gbl...
> http://www.aspfaq.com/2039
>
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>
>
>
> "Keith" <@.> wrote in message news:#6j93AIdEHA.596@TK2MSFTNGP11.phx.gbl...
want[color=darkred]
an[color=darkred]
>
>
| |
| Aaron [SQL Server MVP] 2004-07-28, 3:55 pm |
| > By the way nice servername Aaron; MacGyver ;)
I have some much more interesting ones. I have dual workstations at work,
and at one point they were called cromagnon and neanderthal (one machine is
still neanderthal). I've had airwolf and papasmurf ... some of us always
have fun with our workstation and server names; others are pretty boring
(first initial last name).
A
| |
|
| Thank you
That worked fine.
Is it possible (and if so how) to check if when a file is deleted the folder
it is in would be empty, and if this is the case, delete the folder too?
Thanks
"Christopher Brandsdal" <brandsdal@binaer.no> wrote in message
news:%238RsT%23JdEHA.644@tk2msftngp13.phx.gbl...
> Try this..
> If it doesen't work, then just change the strFilePath....
> Just to test that the string is valid, insert the followingtag, run the
> code, and se if the result is the same as the actual path:
>
> <%=Server.MapPath("../../../sections/policies/files/policies/" &
> RS_Remove_Policy.Fields.Item("Policy_Category") & "/" &
> RS_Remove_Policy.Fields.Item("Policy_File_Name"))%>
>
>
> Here is the code withe the string you provided! Try this:
>
>
> Dim objFSO
> Dim objDelFile
> Dim strFilePath
>
> strFilePath= "../../../sections/policies/files/policies/" &
> RS_Remove_Policy.Fields.Item("Policy_Category") & "/" &
> RS_Remove_Policy.Fields.Item("Policy_File_Name")
> on error resume next
> Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
> Set objDelFile = objFSO.GetFile(Server.MapPath(strFilePath))
> objDelFile.Delete
>
> Set objDelFile = nothing
> Set objFSO = nothing
>
>
>
>
>
> "Keith" <@.> wrote in message
news:urAqxgIdEHA.2664@TK2MSFTNGP09.phx.gbl...
> familiar
code[color=darkred]
> news:#6j93AIdEHA.596@TK2MSFTNGP11.phx.gbl...
now[color=darkred]
so[color=darkred]
>
>
|
|
|
|