Advertisement
Advertisement
| 07.20.2008 at 12:19PM PDT, ID: 23580388 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: |
Public Sub Upload2()
'Code for uploading any file into database.
Dim buffer As String
Dim chunksize, remainder As Long
Dim amount_written As Long
Dim ORide As Boolean
N1 = PID
n2 = POID
ORide = False
'Screen.MousePointer = 11
'strFilter = ahtAddFilterItem(strFilter, "PDF Files (*.PDF)", "*.pdf")
strFilter = ahtAddFilterItem(strFilter, "Any Files (*.*)", "*.*")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Select file to upload...", _
Flags:=ahtOFN_HIDEREADONLY)
st1 = strInputFileName
'st2 = Left(strInputFileName, Len(strInputFileName) - Len(Dir(strInputFileName)))
st2 = Dir(strInputFileName)
If st1 <> "" Then
x1 = MsgBox("Upload: " & vbCrLf & vbCrLf & st2 & vbCrLf & vbCrLf & "into database?", vbYesNo, "File Upload")
Else
x1 = vbNo
End If
If x1 <> vbYes Then
ORide = False
MsgBox "No information uploaded", vbExclamation, "File Upload Cancelled."
Else
'Document2 = st2
DTitle2 = st2
Me.requery
Refresh
'Document2.Locked = False
'Create the OraSession Object.
Set OraSession = CreateObject("OracleInProcServer.XOraSession")
'Create the OraDatabase Object by opening a connection to Oracle.
Set OraDatabase = OraSession.OpenDatabase(OracleSite, "USERNAME/PASSWORD", 0&)
'Create the OraDynaset Object
Set OraDynaset = OraDatabase.CreateDynaset("select * from po_link where proj_id = " & N1 & " and po_id = " & n2, 0&)
Set PartDesc = OraDynaset.Fields("Attachment_C").Value
chunksize = 32000
'Re adjust the buffer size
buffer = String$(chunksize, 32)
fnum = FreeFile
'Open the file.
Open st1 For Binary As #fnum
'Open "partdesc.dat" For Binary As #fnum
'set the offset and PollingAmount properties for piece wiseWrite operation
PartDesc.Offset = 1
PartDesc.PollingAmount = LOF(fnum)
remainder = LOF(fnum)
If (LOF(fnum) = 0) Then
MsgBox "File size is zero. Make sure that existence of File and its path are correct"
Exit Sub
End If
'Lock the row for write operation
OraDynaset.Edit
Get #fnum, , buffer
'Do first write operation
amount_written = PartDesc.Write(buffer, chunksize, ORALOB_FIRST_PIECE)
While PartDesc.Status = ORALOB_NEED_DATA
remainder = remainder - chunksize
If remainder < chunksize Then
piecetype = ORALOB_LAST_PIECE
chunksize = remainder
Else
piecetype = ORALOB_NEXT_PIECE
End If
Get #fnum, , buffer
amount_written = PartDesc.Write(buffer, chunksize, piecetype)
Wend
Close fnum
'call Update method to commit the transaction
OraDynaset.update
OraDynaset.Close
'Free LOB
Set PartDesc = Nothing
OraDatabase.Close
Set OraSession = Nothing
checkset
MsgBox "File: " & vbCrLf & vbCrLf & st2 & vbCrLf & vbCrLf & " uploaded successfully.", vbInformation, "Upload Complete"
End If
'Screen.MousePointer = 0
End Sub
|