Forums

ASP

This topic is locked

Replace / with backward \ slashes?

Posted 11 Apr 2002 18:57:14
1
has voted
11 Apr 2002 18:57:14 Jean-Marie Bonnar posted:
Hi Guys (& Gals),

I was wondering if/how I could go about changing a URL path to an image on an ASP page so that it can be converted (replace) from /album/Renault/image.jpg to \album\Renault\image.jpg so that I may then use it in my code with Server.MapPath (-->see arrow below in the code) so that I can use the FSO to delete the image from the server before I delete the record? I have need to prefix the image with the full path because I have to also insert a Gallery name variable as part of the URL path to the image so therefore during upload this is what is captured rather than just the filename for insertion into the database.
(rsMemberGalleryPics.Fields.Item("Gallery_Pic_URL".Value) below is the full path to the image which needs to be converted to the path to the file on the server to be able to delete it using the FSO. I hope this makes sense to someone. lol
Here is my code so far:
<% 'Jean-Marie added FSO Functions here to enable deletion of images from the server
Function newFileSystemObject()
set newFileSystemObject=Server.CreateObject("Scripting.FileSystemObject"
End Function
%>
<%
Function fileExists(aFileSpec)
fileExists=newFileSystemObject.fileExists(aFileSpec)
End Function 'end of FSO Functions added
%>

<%
' *** Delete Record: construct a sql delete statement and execute it

If (CStr(Request("MM_delete") <> "" And CStr(Request("MM_recordId") <> "" Then

' create the sql delete statement
MM_editQuery = "delete from " & MM_editTable & " where " & MM_editColumn & " = " & MM_recordId

If (Not MM_abortEdit) Then
' execute the delete
Set MM_editCmd = Server.CreateObject("ADODB.Command"
MM_editCmd.ActiveConnection = MM_editConnection
If Request.Form("form_delete" <> "" Then 'this line of code added to make FSO code contingent on submission of the form
Set File = CreateObject("Scripting.FileSystemObject"
ImagePath = Server.MapPath-->("..\album\..\"
ImagePath = ImagePath & "\" & (rsMemberGalleryPics.Fields.Item("Gallery_Pic_URL".Value)
' check if file exists and if true delete the file
If fileExists(ImagePath) Then
File.DeleteFile(ImagePath)
End If
End If
'end of FSO code added

I hope this all comes out alright on the forum because it's not on the Preview, but I'll post anyway?
Thank you in advance for you help.

Jean-Marie

Edited by - Jean-Marie on 11 Apr 2002 18:58:15

Edited by - Jean-Marie on 11 Apr 2002 18:59:57

Edited by - Jean-Marie on 11 Apr 2002 19:01:07

Replies

Replied 11 Apr 2002 22:37:26
11 Apr 2002 22:37:26 Owen Eastwick replied:
Have you tried:

---
---
ImagePath = ImagePath & "\" & (rsMemberGalleryPics.Fields.Item("Gallery_Pic_URL".Value)
ImagePath = Replace(ImagePath, "\", "/"
---
---

Regards

Owen.

Multiple Parameter UD4 / Access 2000 Database Search Tutorial:
www.tdsf.co.uk/tdsfdemo
Replied 13 Apr 2002 02:33:13
13 Apr 2002 02:33:13 Hank Tan-Tenn replied:
Hmm...I don't get it. Doesn't Server.MapPath automatically convert any "/" to "\"? I usually just build the full path to a file, then MapPath it.

Reference:
www.devguru.com/Technologies/asp/quickref/server_mappath.html
Replied 13 Apr 2002 03:06:29
13 Apr 2002 03:06:29 Jean-Marie Bonnar replied:
Hi Owen,

I must still be doing something wrong because I still can't get it to work.
I guess I really need to get the filename by itself to map it properly? When prefaced by the variable album names it's not working?

Regards,

Jean-Marie

Reply to this topic