Skip to main content
Inspiring
July 8, 2008
Question

FileSystemObject ?

  • July 8, 2008
  • 8 replies
  • 421 views
Below is a sample of what I am doing. It checks if an image exists and
on the server. If the product image doesn't exist, it looks for group
image. If that one doesn't exist, it should display a "no image"
message. That's it in a nutshell.

I was wondering if there's anything glaringly wrong...Thanks.

<%Set fs=Server.CreateObject("Scripting.FileSystemObject")%>
<% strFile1 = "f:\path\to\images\science\DD" &
(rsRecordset.Fields.Item("ProductID").Value) & ".jpg" %>
<% strFile2 = "f:\path\to\images\science\DD" &
(rsRecordset.Fields.Item("gid").Value) & ".jpg"%>
<%If ((fs.FileExists(strFile1))=true) Then%>.
<img
src=" http://www.domain.com/prodPix/science/DD<%=(rsRecordset.Fields.Item("ProductTable").Value)%>.jpg"
alt="<%=(rsRecordset.Fields.Item("Name").Value)%>"/>
<% If ((fs.FileExists(strFile1))<>true AND
((fs.FileExists(strFile2))=true)) Then %>
..<img
src=" http://www.domain.com/prodPix/science/DD<%=(rsRecordset.Fields.Item("GroupID").Value)%>.jpg"
alt="<%=(rsRecordset.Fields.Item("Name").Value)%>"/><br />
<span class="style2">Photo is of Parent Grouping</span>
<% If ((fs.FileExists(strFile1))<>true)
AND((fs.FileExists(strFile2))<>true) Then %>
<div class="rightcontent">No Image Available </div>
<%end if 'strFile1 %>
<%end if 'strFile2 %>
<%end if 'both false %>
<br />
This topic has been closed for replies.

8 replies

Inspiring
July 9, 2008
Art wrote:
> So what does your whole script block look like?

<% Set fso = createobject("scripting.filesystemobject") %>

<% If fso.FileExists (server.mappath("/images/products/thumbs/" &
(rsProducts.Fields.Item("itm_wpicture").Value))) then %>
<a
href="/shop/view.asp?ID=<%=(rsProducts.Fields.Item("itm_item").Value)%>"><img
src="/images/products/thumbs/<%=(rsProducts.Fields.Item("itm_wpicture").Value)%>"
alt="<%=(rsProducts.Fields.Item("itm_item").Value)%>" width="100"
height="100" border="0"
title="<%=(rsProducts.Fields.Item("itm_item").Value)%>" /></a>
<% Else %>
<img src="/images/manufacturer/thumbs/nologo.jpg" alt="" width="100"
height="100" border="0" /></a>
<%End if%>
Inspiring
July 9, 2008
Art wrote:
> Art wrote:
>> So what does your whole script block look like?
> I'm having a hard time visualizing how I should plug that into my own
> example .

This is what your code looks like:

<% strFile1 = "f:\path\to\images\science\DD" &
(rsRecordset.Fields.Item("ProductID").Value) & ".jpg" %>

It should look like this:

<% strFile1 = Server.MapPath("\images\science\DD" &
(rsRecordset.Fields.Item("ProductID").Value) & ".jpg") %>

http://www.w3schools.com/ASP/met_mappath.asp

Steve
Inspiring
July 8, 2008
Art wrote:
> So what does your whole script block look like?
I'm having a hard time visualizing how I should plug that into my own
example .
Inspiring
July 8, 2008
So what does your whole script block look like?
Inspiring
July 8, 2008
Art wrote:
> Dooza wrote:
>> Art wrote:
>>> I probably found the solution to this. It turns out my host put my
>>> sites on different servers...:( Consequently, the script couldn't
>>> find the file.
>>
>> I use:
>> <% If fso.FileExists (server.mappath("/images/..........
>>
>> That way I don't concern myself with the physical path, the server
>> does it for me, as it knows what the path is already.
>>
>> Steve
> Thanks Steve,
> That looks like it would work for my main site. My problem is that I'm
> using it across 3 domain names and the problem I just discovered is that
> the two domains that use this are on different servers completely.
>
> I'm in the process of fixing this but I think when I am done, I'll need
> to use the direct path for these other two domains once they get moved
> to the same location.
>
> Thanks for the suggestion.

It should work for all your servers, doesn't matter what the path to
your web files are, this will put the correct one in no matter which
server your on, give it ago and see.

Steve
Inspiring
July 8, 2008
Dooza wrote:
> Art wrote:
>> I probably found the solution to this. It turns out my host put my
>> sites on different servers...:( Consequently, the script couldn't find
>> the file.
>
> I use:
> <% If fso.FileExists (server.mappath("/images/..........
>
> That way I don't concern myself with the physical path, the server does
> it for me, as it knows what the path is already.
>
> Steve
Thanks Steve,
That looks like it would work for my main site. My problem is that I'm
using it across 3 domain names and the problem I just discovered is that
the two domains that use this are on different servers completely.

I'm in the process of fixing this but I think when I am done, I'll need
to use the direct path for these other two domains once they get moved
to the same location.

Thanks for the suggestion.
Inspiring
July 8, 2008
Art wrote:
> I probably found the solution to this. It turns out my host put my sites
> on different servers...:( Consequently, the script couldn't find the file.

I use:
<% If fso.FileExists (server.mappath("/images/..........

That way I don't concern myself with the physical path, the server does
it for me, as it knows what the path is already.

Steve
Inspiring
July 8, 2008
I probably found the solution to this. It turns out my host put my sites
on different servers...:( Consequently, the script couldn't find the file.

> Below is a sample of what I am doing. It checks if an image exists and
> on the server. If the product image doesn't exist, it looks for group
> image. If that one doesn't exist, it should display a "no image"
> message. That's it in a nutshell.
>
> I was wondering if there's anything glaringly wrong...Thanks.
>
> <%Set fs=Server.CreateObject("Scripting.FileSystemObject")%>
> <% strFile1 = "f:\path\to\images\science\DD" &
> (rsRecordset.Fields.Item("ProductID").Value) & ".jpg" %>
> <% strFile2 = "f:\path\to\images\science\DD" &
> (rsRecordset.Fields.Item("gid").Value) & ".jpg"%>
> <%If ((fs.FileExists(strFile1))=true) Then%>.
> <img
> src=" http://www.domain.com/prodPix/science/DD<%=(rsRecordset.Fields.Item("ProductTable").Value)%>.jpg"
> alt="<%=(rsRecordset.Fields.Item("Name").Value)%>"/>
> <% If ((fs.FileExists(strFile1))<>true AND
> ((fs.FileExists(strFile2))=true)) Then %>
> ..<img
> src=" http://www.domain.com/prodPix/science/DD<%=(rsRecordset.Fields.Item("GroupID").Value)%>.jpg"
> alt="<%=(rsRecordset.Fields.Item("Name").Value)%>"/><br />
> <span class="style2">Photo is of Parent Grouping</span>
> <% If ((fs.FileExists(strFile1))<>true)
> AND((fs.FileExists(strFile2))<>true) Then %>
> <div class="rightcontent">No Image Available </div>
> <%end if 'strFile1 %>
> <%end if 'strFile2 %>
> <%end if 'both false %>
> <br />