Foros del Web » Programando para Internet » ASP Clásico »

Error al subir archivo ASPUpload

Estas en el tema de Error al subir archivo ASPUpload en el foro de ASP Clásico en Foros del Web. Tengo el código (que comparto abajo), que básicamente mediante un formulario y con ayuda del componente ASPUpload, subo un archivo excel al servidor, una vez ...
  #1 (permalink)  
Antiguo 01/11/2013, 14:11
 
Fecha de Ingreso: enero-2006
Mensajes: 169
Antigüedad: 18 años, 3 meses
Puntos: 0
Pregunta Error al subir archivo ASPUpload

Tengo el código (que comparto abajo), que básicamente mediante un formulario y con ayuda del componente ASPUpload, subo un archivo excel al servidor, una vez guardado leo el excel e imprimo su contenido.
El detalle (extraño para mi) es que al momento de guardar el archivo. lo hace sin problemas, pero al apretar F5 o volver a subir el archivo, marca el siguiente error en el servidor:
Cita:
Persits.Upload.1 error '800a001a'
The process cannot access the file because it is being used by another process.
file.asp, line 89
De manera local no marca error, ahora, si después de que me marca el error arriba mencionado, dejo pasar aproximadamente 2 min y refresco la pagina (F5), si sube el archivo y no marca el error.
Entonces "supongo" existe alguna configuración en el servidor que determina el tiempo que queda abierto un archivo, la pregunta del millón es ¿Alguien sabe que parámetro controla esta parte del archivo?
[PHP]
<% Option Explicit %>
<% Response.expires = 0 %>
<html>
<body>
<header>
<link href="inc/asp/ilatina.css" rel="stylesheet">
<SCRIPT type="text/javascript">
function validate_file_format(field_name, allowed_ext) {
obj1 = document.Form_SubirExcel;
var temp_field = 'obj1.' + field_name + '.value';
field_value = eval(temp_field);
if (field_value.length <= 0) {
alert('Seleccione un archivo con extension: ' + allowed_ext);
return false;
}
else{
//if (field_value != "") {
var file_ext = (field_value.substring((field_value.lastIndexOf('. ') + 1)).toLowerCase());
ext = allowed_ext.split(',');
var allow = 0;
for (var i = 0; i < ext.length; i++) {
if (ext[i] == file_ext) {
allow = 1;

}
}
if (!allow) {
alert('Formato de archivo invalido. Por favor suba archivo con extension: ' + allowed_ext);
return false;
}
}
}
</SCRIPT>
</header>
<%
if Request.QueryString("subir_archivo")=1 then

Dim objUpload, carpeta, strNombreFichero
'SUBIR ARCHIVO AL SERVIDOR
Dim Count, ID_ODT, objFich, ins_ExtensionFile, ruta
Set objUpload = Server.CreateObject("Persits.Upload.1")
objUpload.CodePage = 65001
Count = objUpload.Save

'recuperamos los campos del formulario
ID_ODT = "34567"

'si no ha subido ningún fichero, le avisamos
if Count = 0 then
Response.Write("No has subido ningún fichero")
else
'accedemos al fichero por su nombre en el formulario
Set objFich = objUpload.Files("frmArchivo")
carpeta = Server.MapPath("\Carpeta")
strNombreFichero = "Archivo_" & ID_ODT & "." & ins_ExtensionFile
response.Write "file= " & carpeta & "\" & strNombreFichero
'Guardamos el archivo
ruta = carpeta & "\" & strNombreFichero
objFich.SaveAs ruta

'Cerramos y limpiamos
set objUpload = nothing
set objFich = nothing
end if
'FIN SUBIR ARCHIVO A SERVIDOR
end if
%>

...continua abajo
__________________
"La adulación es una moneda que empobrece al que la recibe"
  #2 (permalink)  
Antiguo 01/11/2013, 14:12
 
Fecha de Ingreso: enero-2006
Mensajes: 169
Antigüedad: 18 años, 3 meses
Puntos: 0
Respuesta: Error al subir archivo ASPUpload

Código PHP:
 <form name="Form_SubirExcel" action="carga_distribucion.asp?subir_archivo=1" method="post" enctype="multipart/form-data">
        <
table width="750" border="0" align="center" height="35">
          <
tr class= "Titulo"
            <
td>Carga de distribuci&oacute;n por paquetes</td>
            <
td><!--<a href="cot_autoriza.asp"><img src="http://www.forosdelweb.com/f15/fle_colores_izq.jpg" width="30" border="0" height="34"></a>-->
                <
a href="javascript:window.history.back();"><img src="http://www.forosdelweb.com/f15/fle_colores_izq.jpg" width="30" border="0" height="34"></a>
            </
td>
          </
tr>
        </
table>
        <
table width="750" border="0" cellspacing="0" cellpadding="0" align="center">
            <
tr><td colspan="5"
                <
table width="750" border="1" cellspacing="0" cellpadding="0" bordercolor="#C0C0C0" align="center">
                    <
tr class="Titulotabla"
                        <
td colspan="2">Seleccione archivo</td>
                    </
tr>
                    <
tr class="fondotabla2"
                        <
td align="right"><input type="file" name="frmArchivo" /></td>
                        <
td><input type="submit" value="Subir archivo" onclick="return validate_file_format('frmArchivo','xls,xlsx')" /></td>
                    </
tr>
                </
table>
            </
td></tr>
        
        </
table>
        </
form>
<%
    if 
Request.QueryString("subir_archivo")=1 then
        
'Dim oConexion 
        Dim aDatos, aInserciones, msjError, reg_vacio, reg_num
        Dim sFilePath, sDataDir, sSheetName, sFileConnectionString, sFileSQL, oFileCN
        Dim oRS, aSourceData, iCont
        

        msjError = ""
        reg_vacio = 0
        reg_num = 0

        '
Set oConexion Server.CreateObject("ADODB.Connection")

        
sFilePath server.MapPath("Carpeta\excel.xls"'path del archivo xls
        sDataDir = server.MapPath("carpeta") '
path de directotio que lo contiene
        sSheetName 
"Hoja1" ' nombre de la hoja donde estan los registros

        '
response.Write sFilePath

        sFileConnectionString 
"Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ="&sFilePath&";DefaultDir="&sDataDir&";"
        
sFileSQL "SELECT * FROM [" sSheetName "$]"
        
set oFileCN server.createobject("ADODB.Connection"'creo objeto adodb
        oFileCN.Open sFileConnectionString '
abro el exel
        set oRS 
oFileCN.Execute(sFileSQL'selecciono los registros
        if not oRS.EOF then '
si es distinto de EOF obtengo un array con los valores de las columnas
            aSourceData 
oRS.getRows() ' asigna las filas a la variable aSourceData 
        end if

        '
SI DIO CLICK EN "CARGAR DISTRIBUCION" SE PROCEDE A GUARDAR LOS REGISTROS EN LA TABLA
        
if request.QueryString("btn_carga_dist")=1 then
            dim datos_excel
(11'11 por que son del 0 al 11, en total, 12 columnas en el excel

            Do While NOT oRs.EOF
                For iCont = 0 to oRs.Fields.Count - 1
                    if oRs.Fields(iCont)<>"" then
                        reg_vacio = reg_vacio + 0
                    else
                        reg_vacio = reg_vacio + 1
                    end if
                Next


                if reg_vacio <> 12 then
                    response.Write "reg_num= " & reg_num & "<br>"
                    For iCont = 0 to oRs.Fields.Count - 1
                        datos_excel(iCont) =  oRs.Fields(iCont)
                        response.Write "Posicion(" & iCont & ")= " & datos_excel(iCont) & "<br>"
                    Next
                end if

                    '
For iCont 0 to oRs.Fields.Count 1
                        
'response.Write "Posicion(" & iCont & ")= " & datos_excel(iCont) & "<br>"
                   '
Next
    
                
if reg_vacio <> 12 then
                    oRs
.MoveNext
                    reg_num 
reg_num 1
                    reg_vacio 
0
                
else
                    exit Do
                
end if
            
Loop
        
else
            
'Validamos que los campos obligatorios esten llenos en el excel
            oRs.MoveFirst
            Do While NOT oRs.EOF
                For iCont = 0 to oRs.Fields.Count - 1
                    if oRs.Fields(iCont)<>"" then
                        reg_vacio = reg_vacio + 0
                    else
                        reg_vacio = reg_vacio + 1
                    end if
                Next

                if reg_vacio <> 12 then 
                    For iCont = 0 to oRs.Fields.Count - 1
                        if oRs.Fields(0)<>"" then
                        else
                            msjError = "LA COLUMNA '
NO SUCURSAL RECEPTORA' NO PUEDE ESTAR VACIA EN EL ARCHIVO EXCEL"
                            exit for
                        end if
                        if oRs.Fields(4)<>"" then
                        else
                            msjError = "LA COLUMNA '
PAQUETES' NO PUEDE ESTAR VACIA EN EL ARCHIVO EXCEL"
                            exit for
                        end if
                        if oRs.Fields(6)<>"" then
                        else
                            msjError = "LA COLUMNA '
SKU' NO PUEDE ESTAR VACIA EN EL ARCHIVO EXCEL"
                            exit for
                        end if
                        if oRs.Fields(7)<>"" then
                        else
                            msjError = "LA COLUMNA '
ODTi' NO PUEDE ESTAR VACIA EN EL ARCHIVO EXCEL"
                            exit for
                        end if
                    Next
                end if

                if reg_vacio <> 12 AND msjError="" then
                    oRs.MoveNext
                    reg_vacio = 0
                else
                    exit Do
                end if
            Loop


            if msjError<>"" then '
Si existe error en el archivo excelindicamos el mismo
                Response
.Write "<p align='center'><font color='RED'><strong>" msjError "</strong></font></p>"
            
else 'Pintamos el archivo excel
                '
Mostramos los nombres de los campos (cabecera
                
response.Write "<table width='750' border='0' cellspacing='0' cellpadding='0' align='center'>"
                
response.Write "<tr><td>" 
                
response.Write "<table width='750' border='1' cellspacing='0' cellpadding='0' bordercolor='#C0C0C0' align='center'>"
                
response.Write "<tr class='Titulotabla'>"
                
For iCont 0 to oRs.Fields.Count 
                  Response
.Write "<td>" oRs.Fields(iCont).name "<td/>"
                
Next 
                response
.Write "</tr>"

                'response.Write "error = " & msjError
    
                oRs.MoveFirst
                Do While NOT oRs.EOF
        
                    For iCont = 0 to oRs.Fields.Count - 1
                        if oRs.Fields(iCont)<>"" then
                            reg_vacio = reg_vacio + 0
                        else
                            reg_vacio = reg_vacio + 1
                        end if
                    Next
        
                    if reg_vacio <> 12 then
                        response.Write "<tr class='
fondotabla2>"
                        For iCont = 0 to oRs.Fields.Count - 1
                            if oRs.Fields(iCont)<>"" then    
                                Response.Write "
<td>" & oRs.Fields(iCont) & "<td/>"
                            else
                                Response.Write "
<td>&nbsp;<td/>"
                            end if
                        Next
                    end if
                    response.Write "
</tr>"
        
                    if reg_vacio <> 12 then
                        oRs.MoveNext
                        reg_vacio = 0
                    else
                        exit Do
                    end if

                Loop
                response.Write "
</td></tr>"
                response.Write "
</table>"
            end if
        end if

        oRS.Close
        set oRS = nothing
        oFileCN.Close
        set oFileCN = nothing
    end if
%>

    </body>
</html> 
Gracias de antemano.
__________________
"La adulación es una moneda que empobrece al que la recibe"

Etiquetas: asp, form, html
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:14.