image
Inicio » Foros » ASP

ASP

cargar access con recordset de FSO

Volver al foro | Responder | Añadir nuevo tema


De: Enrique Alejandro Ogalde
Fecha: 14/09/2005
Mensaje:

Hola. Necesito completar este c{odigo que me lista los archivos de un folder en el servidor y cargarlo en una Access.

Acá va el code:

<%
'**********
'kc_fsoFiles
'Purpose:
' 1. To create a recordset using the FSO object and ADODB
' 2. Allows you to exclude files from the recordset if needed
'Use:
' 1. Call the function when you're ready to open the recordset
' and output it onto the page.
' example:
'Dim rsFSO, strPath
'strPath = Server.MapPath("ordenesFSOStuff")
' Set rsFSO = kc_fsoFiles(strPath, "_")
' The "_" will exclude all files beginning with
' an underscore
'**********
Function kc_fsoFiles(theFolder, Exclude)
Dim rsFSO, objFSO, objFolder, File
Const adInteger = 3
Const adDate = 7
Const adVarChar = 200

'create an ADODB.Recordset and call it rsFSO
Set rsFSO = Server.CreateObject("ADODB.Recordset")

'Open the FSO object
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

'go get the folder to output it's contents
Set objFolder = objFSO.GetFolder(theFolder)

'Now get rid of the objFSO since we're done with it.
Set objFSO = Nothing

'create the various rows of the recordset
With rsFSO.Fields
.Append "Name", adVarChar, 200
.Append "Type", adVarChar, 200
.Append "DateCreated", adDate
.Append "DateLastAccessed", adDate
.Append "DateLastModified", adDate
.Append "Size", adInteger
.Append "TotalFileCount", adInteger
End With
rsFSO.Open()

'Now let's find all the files in the folder
For Each File In objFolder.Files

'hide any file that begins with the character to exclude
If (Left(File.Name, 1)) <> Exclude Then
rsFSO.AddNew
rsFSO("Name") = File.Name
rsFSO("Type") = File.Type
rsFSO("DateCreated") = File.DateCreated
rsFSO("DateLastAccessed") = File.DateLastAccessed
rsFSO("DateLastModified") = File.DateLastModified
rsFSO("Size") = File.Size
rsFSO.Update
End If

Next

'And finally, let's declare how we want the files
'sorted on the page. In this example, we are sorting
'by File Type in descending order,
'then by Name in an ascending order.
rsFSO.Sort = "name asc"

'Now get out of the objFolder since we're done with it.
Set objFolder = Nothing

'now make sure we are at the beginning of the recordset
'not necessarily needed, but let's do it just to be sure.
rsFSO.MoveFirst()
Set kc_fsoFiles = rsFSO

End Function

'Now let's call the function and open the recordset on the page
'the folder we will be displaying
Dim strFolder : strFolder = (Server.MapPath ("ordenes") & ""&fcount&"")

'the actual recordset we will be creating with the kc_fsoFiles function
Dim rsFSO 'now let's call the function and open the recordset

'we will exclude all files beginning with a "_"
Set rsFSO = kc_fsoFiles(strFolder, "_")

'now we'll create a loop and start displaying the folder
'contents with our recordset. Of course, this is just a
'simple example and not very well formatted, i.e., not in
'a table, but it gets the point across on how you can
'ouput the recordset on the page.
While Not rsFSO.EOF
%>
<form name="form1" method="post" action="">
<table width="100%" style="
BORDER-bottom: rgb(102,102,102) 1px solid width="100%">
<!--DWLayoutTable-->
<tr>
<td class=le_ch width="81" height="124"> <div align="center">
<input class=in_contac type="checkbox" name="<%= rsFSO("Name").Value %>" value="<%= rsFSO("Name").Value %>">
<br>
<%= rsFSO("Name").Value %>
<input name="nom" type="hidden" id="ver" value="<%= rsFSO("name").Value %>
<%= rsFSO("TotalFileCount").Value %> </p></td>
<td> <div align="center">
</div></td>
<td width="174" valign="middle" class=le_az> <p align="center"><img src="http://www.zoomlab.com.ar/ordenes/<%=fcount%>/<%= rsFSO("Name").Value %>" width="120" border="1" bordercolor=cccccc id=ipreview></p></td>
<td width="108"> <p align="center">
<select class=in_contac name="<%= rsFSO("Name").Value %>">
<option value="1" selected>1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
<option value="32">32</option>
<option value="33">33</option>
<option value="34">34</option>
<option value="35">35</option>
<option value="36">36</option>
<option value="37">37</option>
<option value="38">38</option>
<option value="39">39</option>
<option value="40">40</option>
</select>
<br>
</td>
<td width="93"><!--DWLayoutEmptyCell-->&nbsp;</td>
</tr>
</table>
</form>
<p>
<%
'and let's move to the next record
rsFso.MoveNext()
Wend

'finally, close out the recordset
rsFSO.close()
Set rsFSO = Nothing
%>



Volver al foro | Responder | Añadir nuevo tema

Quizás le interese:

WebEstilo.com no se hace responsable de las opiniones que los usuarios puedan verter en cualquiera de los foros existentes.

Si te solucionó el problema pulsa en G+1


Gracias!






Comparte



Última modificación:31 de Agosto de 2017. Spain - Espa�a.
© 1998-2004 por . Todos los derechos reservados.