Afficher une ligne particulière d'un fichier en ASP
s2.asp
<% function ligne(fichier,num) dim k,inF set inF=FSO.openTextFile(fichier,1,false) k = 1 while k < num and not inF.atEndOfStream inF.skipLine : k = k + 1 wend if not inF.atEndOfStream then ligne = inF.readLine inF.close end function %>
<%function navig(deb,nb,total) dim URL,QUERY,cherche,temp,prec ' récupération de l'URL et de la Query URL = Request.ServerVariables("SCRIPT_NAME") QUERY = Request.ServerVariables("QUERY_STRING") ' un début est indiqué ? si oui, on vire cherche = instr(QUERY,"deb=") if cherche = 1 then QUERY = "" elseif cherche > 1 then QUERY = left(QUERY,cherche-2) end if ' préparation de la future query if QUERY = "" then QUERY = "?deb=" else QUERY = "?" & QUERY & "&deb=" ' chaîne de navigation temp = "" : prec = deb - nb if prec < 1 then prec = 1 if deb > 1 then ' s'il y a des fiches précédentes temp = "<A href='" & URL & QUERY & "1'>Début</A> " _ & "<A href='" & URL & QUERY & prec & "'>Précédentes</A> " end if if (deb+nb) <= total then ' s'il y a des fiches suivantes temp = temp & "<A href='" & URL & QUERY & (deb+nb) & "'>Suivantes</A> " _ & "<A href='" & URL & QUERY & (total-nb+1) & "'>Fin</A>" end if ' retourne le résultat navig = temp end function%>
<% SQL="SELECT * FROM [TABLE]" Set RS = server.createobject("ADODB.Recordset") RS.Open SQL,Conn , 3, 3
nmb = 4 ' nombre de fiches par page deb = 1 ' première fiche if request.queryString("deb")<>"" then ' si queryString deb = cInt(request.queryString("deb")) end if
if RS.recordcount >= deb then ' des fiches à afficher ? for A=1 to RS.recordcount ' pour chaque fiche if A >= deb then ' si ok, affiche %><%=RS("champ")%><br> <%end if if A = (deb + nmb - 1) then ' c'est fini ! exit for else RS.MOVENEXT ' fiche suivante end if next end if %> <br> <%=navig(deb,nmb,RS.recordcount)%>
sens = request.querystring("sens") col = request.querystring("col")
dim tri : redim tri(uBound(fruits))
for i = 0 to uBound(fruits)-1 for k = 0 to i test = false if tri(k) = "" then test = true elseif sens = "up" then test = (fruits(i,col) < fruits(tri(k),col)) elseif sens = "dn" then test =(fruits(i,col) > fruits(tri(k),col)) end if if test then temp = i for m = k to i temp2 = tri(m) : tri(m) = temp : temp = temp2 next exit for end if next next %>
<% set FSO = _ Server.CreateObject("Scripting.FileSystemObject") fn=lcase(Request.ServerVariables("SCRIPT_NAME")) ' si c'est la version française if instr(fn,"_fr.asp") then fn2=replace(fn,"_fr","_us") ' et que la version anglaise existe if FSO.fileExists(server.mapPath(fn2)) then %> <A HREF="<%=fn2%>">English version</A> <% end if ' sinon si c'est la version anglaise elseif instr(fn,"_us.asp") then fn2=replace(fn,"_us","_fr") ' et que la version française existe if FSO.fileExists(server.mapPath(fn2)) then %> <A HREF="<%=fn2%>">Version française</A> <% end if end if %>
s8.php
<? $fn = strtolower(basename($PHP_SELF)); // si c'est la version française if(strpos($fn,"_fr.php")) { $fn2 = str_replace("_fr","_us",$fn); // et que la version anglaise existe if(file_exists($fn2)) { ?> <A HREF="<? echo $fn2; ?>">English version</A> <? } // sinon si c'est la version anglaise elseif(strpos($fn,"_us.php")) { $fn2 = str_replace("_us","_fr",$fn); // et que la version française existe if(file_exists($fn2)) { ?> <A HREF="<? echo $fn2; ?>">Version française</A> <? } } ?>
Répertoire automatique demandé par Amadou pour la Présidence de la Côte d'Ivoire !
s10.asp
<% ' Liste les articles AAAAMMxxxx.ext du répertoire courant ' AAAA et MM étant l'année et le mois de publication dim nommois nommois = Array("","Janvier","Février","Mars","Avril","Mai","Juin" _ ,"Juillet","Août","Septembre","Octobre","Novembre","Décembre") ' Quel choix ? ou alors mois courant mois = request.form("lemois") if mois="" then mois=month(date) else mois=cInt(mois) an = request.form("annee") if an="" then an=year(date) else an=cInt(an) %> <HTML><BODY><title>Exemple</title> <table border=0 cellpadding=2 cellspacing=0> <tr><td colspan=4> <FONT color=#2c4793 size=5><b>Conseil des ministres</b></font><BR><BR> </td></tr><tr bgcolor=#eeeeff><form name="monform" method="post"> <td nowrap> <b>Communiqués de :</b> </td><td> <select name="lemois"> <% for i = 1 to 12 %> <option value="<%=i%>" <%if i=mois then%>SELECTED<%end if%>><%=nommois(i)%> <% next%> </select> </th><td> <select name="annee"> <% for i = 2000 to year(date) %> <option value="<%=i%>" <%if i=an then%>SELECTED<%end if%>><%=i%> <% next%> </select> </th><td> <input type="Submit" value="Lister"> </td> </form></tr> </table> <ol> <% ' Lecture de la liste des communiqués contenus dans le dossier courant Set FSO = Server.CreateObject("Scripting.FileSystemObject") set fc = FSO.getFolder(server.MapPath(".")).files nombre = 0 for each f in fc if left(f.name,6) = (an & right("0"&mois,2)) then%> <li><A href = "<%=f.name%>" target="_blank"><%=f.name%></A><br> <%nombre = nombre + 1 end if next%> </ol> <% ' combien de communiqués ? if nombre=0 then%>Aucun<%else%><%=nombre%><%end if%> communiqué<%if nombre>1 then%>s<%end if%> en <%=nommois(mois) & " " & an%> </BODY></HTML>