Solved

Need to rewrite code for checking if a file exists

Posted on 2016-10-26
3
76 Views
Last Modified: 2016-10-26
I have this script which determines if the file exists:

dim fs
set fs=Server.CreateObject("Scripting.FileSystemObject")
if fs.FileExists("c:\inetpub\wwwroot\"&(rsProducts4("ImageSrc"))&"") then
  response.write ""
else
  response.write" The file c:\inetpub\wwwroot\"&(rsProducts4("ImageSrc"))&" does not exist."
end if
set fs=nothing

My problem is that the database field (rsProducts4("ImageSrc")) has the format images/somefile.jpg
The problem is the slash. I need to change the script where the fs.FileExists evaluation is performed as to interpret the "/" as "\" as I cannot change it in the db. Any adea on how to rewrite this?

Thanks in advance.
0
Comment
Question by:EvertJor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 51

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 41860228
HI,

pls try
 if fs.FileExists("c:\inetpub\wwwroot\" & Replace((rsProducts4("ImageSrc")),"/","\") &"") then

Open in new window

Regards
1
 
LVL 34

Expert Comment

by:ste5an
ID: 41860284
Seems like you're allowing directory traversals.. use Server.MapPath(rsProducts4("ImageSrc")) instead.
1
 

Author Closing Comment

by:EvertJor
ID: 41860501
Yes, that did the trick. Thanks!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question