Permet d'inclure n'importe quel fichier de façon dynmique dans une page ASP. Ce qui ne peut pas être fait avec #include. Merci à Pierre de sites-internet.net de m'avoir mis sur la voie! ;-)
Source / Exemple :
<%
' Checks weither a file exists on the server
' receive relative path to the file + file name
' ex : existFic("images/myImage.gif")
' returns false if file does not exists
' true if file exists or is URL
function existFic(nom)
dim existFic_tmp
' if is URL then say it exists
if lcase(left(nom,7))="http://" then
existFic_tmp = true
else
if nom="" OR isNull(nom) then
existFic_tmp = false
else
dim oFile, f
set oFile = server.createObject("Scripting.FileSystemObject")
If (oFile.FileExists(server.mapPath(nom))) then
existFic_tmp = true
else
existFic_tmp = false
end i
end if
end if
existFic = existFic_tmp
end function
' include dynamique
' can include any text based page
' taking nothing but inside <BODY></BODY> if HTML page
' I take the option that you can't have
' "<HTML>,<HEAD>,</HEAD>,</HTML>" tags without the <body> tag
function incFile(filPath)
dim fichier
fichier = "page.asp"
if existFic(fichier) then
dim fso,fic,fn, contenu, debut, fin
fic=server.mappath(fichier)
set fso=server.createObject("scripting.filesystemObject")
set fn = fso.opentextfile(fic)
contenu = fn.readAll
'takes all after "<BODY>"
debut = inStr(UCase(contenu),"<BODY>")
if debut>0 then
contenu = mid(contenu , debut + 6 , len(contenu) - debut - 1 )
end if
'takes all before "</BODY>"
fin = inStr(UCase(contenu),"</BODY>")
if fin>0 then
contenu = mid(contenu , 1 , fin - 1 )
end if
fn.close
set fso=nothing
incFile = contenu
end if
end function
%>
Conclusion :
ca vous plait?
n'hesitez pas à le dire! ;-)
r.colas@bigfoot.com
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.