2014-12-23 2 views
1

<input type="file">이 ADODB.recordset 용 파일을 잠그고있는 중입니다.입력 형식 = "파일"은 ADODB.Recordset에 대한 파일을 잠급니다.

파일 경로를 하드 코드하면 코드 입력 유형을 사용하여 파일을 찾아보고 하드 코드 된 파일을 선택하면 파일이 잠기고 더 이상 레코드 세트를 통해 액세스 할 수 없습니다.

나는 아무런 성공없이 내가 생각할 수있는 모든 것을 시도했다. 같은 디렉토리 내에서 다른 파일을 선택하거나 코드를 탐색하지 않고 프로세스 단추를 클릭하면 입력 탐색 기능의 결과를 알 수 있습니다.

다음은 관련 html 및 vbscript입니다. 누구든지이 문제를 해결하는 방법에 대한 아이디어가 있습니까?

<html> 
<head> 
<title>Employee Upload</title> 
<HTA:APPLICATION 
    APPLICATIONNAME="Employee Upload" 
    ID="Employee Upload" 
    VERSION="1.0"/> 

</head> 

<body bgcolor="white"> 
<p id="heading" name="heading"><p> 
<div id="container" name="container"> 
<span onClick="document.getElementById('myFile').click();" language="javascript" class="upload"> 
<button>Browse</button> 
<input id="filename" type="text" disabled value=""> 
<input type="file" id="myFile" style="visibility:hidden;display:none;" onchange="document.getElementById('filename').value = this.value;document.getElementById('process').style.visibility = 'visible';" language="javascript"> 
</span> 

<p>Click "Process File" once you have selected the file to upload the new hire data.</p> 

<button id="process" name="process" onclick="loadFile()" style="/*visibility: hidden;*/">Process File</button> 
</div> 
<script language="vbscript"> 

Function loadFile() 
On Error Resume Next 
fileStr = document.all("filename").value 
fileStr = "C:\Users\SeanW\Desktop\imports\NewHires.txt" 
fileDir = Left(fileStr,InStrRev(fileStr,"\")) 
filenameStr = Right(fileStr,Len(fileStr)-InStrRev(fileStr,"\")) 

Set oConn = CreateObject("ADODB.Connection") 
Set oRS = CreateObject("ADODB.Recordset") 
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _ 
      "Data Source=" & fileDir & ";" & _ 
      "Extended Properties=""text;HDR=YES;FMT=Delimited""" 

oRS.Open "SELECT * FROM [" & filenameStr & "]", oConn, 3, 3, 1 

If Err.Number <> 0 Then 
MsgBox "Error Loading File: " & vbCrLf & vbCrLf & Err.Description,vbCritical,"File Load Error" 
oConn.Close 
oRS.Close 
Set oConn = Nothing 
Set oRs = Nothing 
Err.Clear 
Exit Function 
else 

Msgbox "File Loaded Successfully" 
oConn.Close 
oRS.Close 
Set oConn = Nothing 
Set oRs = Nothing 

End If 

End Function 

</script> 
</body> 
</html> 

답변

1

오늘 정확히이 문제가있었습니다. 그때 또한 ADODB.Connection

dim txtfile: txtfile = document.getElementById("filename").Value 
dim fso: set fso = CreateObject("Scripting.FileSystemObject") 
dim tablename: tablename = fso.GetFileName(txtfile) 
' we'll create the folder as a subfolder to the current one 
dim currentfolder: currentfolder = fso.GetAbsolutePathName(".") 

' create new paths until we have a new one 
dim newpath: newpath = fso.BuildPath(currentfolder, fso.GetTempName()) 
do while fso.folderExists(newpath) 
    newpath = fso.BuildPath(currentfolder, fso.GetTempName()) 
loop 

' create the folder & copy the input file 
fso.createFolder newpath 
fso.copyfile txtfile, fso.buildpath(newpath, tablename) 

'connect and process 
ado.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ 
     "Data Source=" & newpath & ";" & _ 
     "Extended Properties=""text;HDR=YES;FMT=Delimited""" 

ado.open 

'... etc 

' clear up the temp folder 
fso.deleteFolder newpath, true 
+0

와 그 방법을 참조하십시오 연결, 하위 폴더에 입력 파일의 복사본을 만들어 주위 가지고 http://stackoverflow.com/questions/37583532/using-file-input-element -in-hta-file-deleted-deleted-selected-file –

관련 문제