By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,853 Members | 842 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,853 IT Pros & Developers. It's quick & easy.

i got the error in llne no235

P: 1
Expand|Select|Wrap|Line Numbers
  1. <%
  2. ' ------------------------------------------------------------------------------
  3. ' Container of Field Properties
  4. Class clsField
  5.     Public FileName
  6.     Public ContentType
  7.     Public Value
  8.     Public FieldName
  9.     Public Length
  10.     Public BinaryData
  11. End Class
  12. ' ------------------------------------------------------------------------------
  13. Class clsUpload
  14. ' ------------------------------------------------------------------------------
  15.     Private nFieldCount
  16.     Private oFields()
  17.     Private psFileFullPath
  18.     Private psError
  19.     Private psFileInputName
  20. ' ------------------------------------------------------------------------------
  21.     Public Property Get Count()
  22.         Count = nFieldCount
  23.     End Property
  24. ' ------------------------------------------------------------------------------
  25.     Public Default Property Get Field(ByRef asFieldName)
  26.         Dim lnLength
  27.         Dim lnIndex
  28.  
  29.         lnLength = UBound(oFields)
  30.  
  31.         If IsNumeric(asFieldName) Then
  32.             If lnLength >= asFieldName And asFieldName > -1 Then
  33.                 Set Field = oFields(asFieldName)
  34.             Else
  35.                 Set Field = New clsField
  36.             End If
  37.         Else
  38.             For lnIndex = 0 To lnLength
  39.                 If LCase(oFields(lnIndex).FieldName) = LCase(asFieldName) Then
  40.                     Set Field = oFields(lnIndex)
  41.                     Exit Property
  42.                 End If
  43.             Next
  44.             Set Field = New clsField
  45.         End If
  46.     End Property
  47. ' ------------------------------------------------------------------------------
  48.     Public Function Exists(ByRef avKeyIndex)
  49.         Exists = Not IndexOf(avKeyIndex) = -1
  50.     End Function
  51. ' ------------------------------------------------------------------------------
  52.     Public Property Get ValueOf(ByRef avKeyIndex)
  53.         Dim lnIndex
  54.         lnIndex = IndexOf(avKeyIndex)
  55.         if lnIndex = -1 Then Exit Property
  56.         ValueOf = oFields(lnIndex).Value
  57.     End Property
  58. ' ------------------------------------------------------------------------------
  59.     Public Property Get FileNameOf(ByRef avKeyIndex)
  60.         Dim lnIndex
  61.         lnIndex = IndexOf(avKeyIndex)
  62.         if lnIndex = -1 Then Exit Property
  63.         FileNameOf = oFields(lnIndex).FileName
  64.     End Property
  65. ' ------------------------------------------------------------------------------
  66.     Public Property Get LengthOf(ByRef avKeyIndex)
  67.         Dim lnIndex
  68.         lnIndex = IndexOf(avKeyIndex)
  69.         if lnIndex = -1 Then Exit Property
  70.         LengthOf = oFields(lnIndex).Length
  71.     End Property
  72. ' ------------------------------------------------------------------------------
  73.     Public Property Get BinaryDataOf(ByRef avKeyIndex)
  74.         Dim lnIndex
  75.         lnIndex = IndexOf(avKeyIndex)
  76.         if lnIndex = -1 Then Exit Property
  77.         BinaryDataOf = oFields(lnIndex).BinaryData
  78.     End Property
  79. ' ------------------------------------------------------------------------------
  80.     Private Function IndexOf(ByVal avKeyIndex)
  81.         Dim lnIndex
  82.  
  83.         If avKeyIndex = "" Then
  84.             IndexOf = -1
  85.         ElseIf IsNumeric(avKeyIndex) Then
  86.             avKeyIndex = CLng(avKeyIndex)
  87.             If nFieldCount > avKeyIndex And avKeyIndex > -1 Then
  88.                 IndexOf = avKeyIndex
  89.             Else
  90.                 IndexOf = -1
  91.             End If
  92.         Else
  93.             For lnIndex = 0 To nFieldCount - 1
  94.                 If LCase(oFields(lnIndex).FieldName) = LCase(avKeyIndex) Then
  95.                     IndexOf = lnIndex
  96.                     Exit Function
  97.                 End If
  98.             Next
  99.             IndexOf = -1
  100.         End If
  101.     End Function
  102. ' ------------------------------------------------------------------------------
  103. Public Property Let FileFullPath(sValue)
  104.     psFileFullPath = sValue
  105. End Property
  106. '___________________________________________________________________________________
  107. Public Property Get FileFullPath()
  108.     FileFullPath = psFileFullPath 
  109. End Property
  110. ' ------------------------------------------------------------------------------
  111. Public Property Let FileInputName(sValue)
  112.     psFileInputName = sValue
  113. End Property
  114. ' --------------------    ----------------------------------------------------------
  115. Public Function Save()
  116.     if psFileFullPath <> "" and psFileInputName <> "" then
  117.         'Save to connectionless client side recordset, write to stream,
  118.         'and persist stream.
  119.  
  120.         'would think you should be able to write directly to
  121.         'stream without recordset, but I could not get that to work
  122.  
  123.         On error resume next
  124.         binData = o.BinaryDataOf(psFileInputName)
  125.  
  126.         set rs = server.createobject("ADODB.RECORDSET")
  127.         rs.fields.append "FileName", 205, LenB(binData)
  128.         rs.open
  129.         rs.addnew
  130.          rs.fields(0).AppendChunk binData 
  131.  
  132.         if err.number = 0 then
  133.             set objStream = Server.CreateObject("ADODB.Stream")
  134.               objStream.Type  = 1
  135.                objStream.Open
  136.              objStream.Write rs.fields("FileName").value 
  137.             objStream.SaveToFile psFileFullPath, 2
  138.             objStream.close
  139.             set objStream = Nothing
  140.  
  141.         ENd if
  142.         rs.close
  143.         set rs = nothing
  144.         psError = Err.Description
  145. else
  146.         psError = "One or more required properties (FileFullPath and/or FileInputName) not set"
  147.  
  148.   End If
  149.  
  150.  
  151. End Function
  152.  
  153. Public Property Get Error()
  154.     Error = psError
  155. End Property
  156.  
  157.  
  158. ' ------------------------------------------------------------------------------
  159.     Public Property Get ContentTypeOf(ByRef avKeyIndex)
  160.         Dim lnIndex
  161.         lnIndex = IndexOf(avKeyIndex)
  162.         if lnIndex = -1 Then Exit Property
  163.         ContentTypeOf = oFields(lnIndex).ContentType
  164.     End Property
  165.  
  166. ' ------------------------------------------------------------------------------
  167.     Private Sub Class_Terminate()
  168.         Dim lnIndex
  169.         For lnIndex = 0 To nFieldCount - 1
  170.             Set oFields(0) = Nothing
  171.         Next
  172.     End Sub
  173. ' ------------------------------------------------------------------------------
  174.     Private Sub Class_Initialize()
  175.  
  176.         Dim lnBytes                ' Bytes received from the client
  177.         Dim lnByteCount            ' Number of bytes received
  178.         Dim lnStartPosition        ' Position at which content begins
  179.         Dim lnEndPosition        ' Position at which content ends
  180.  
  181.         Dim loDic                ' Contains properties of each
  182.                                 ' specific field
  183.                                 ' Local dictionary object(s) 
  184.                                 ' to be appended to class-scope
  185.                                 ' dictioary object.
  186.  
  187.         Dim lnBoundaryBytes        ' Bytes contained within the current boundary
  188.         Dim lnBoundaryStart        ' Position at wich the current boundary begins
  189.                                 ' within the lnBytes binary data.
  190.         Dim lnBoundaryEnd        ' Position at wich the current boundary ends
  191.                                 ' within the lnBytes binary data.
  192.         Dim lnDispositionPosition
  193.  
  194.         Dim lsFieldName            ' Name of the current field being parsed from
  195.                                 ' Binary Data
  196.         Dim lsFileName            ' Name of the file within the current boundary
  197.         Dim lnFileNamePosition    ' Location of file name within current boundary
  198.         Dim loField                ' clsField Object
  199.         Dim lsValue                ' Value of the current field
  200.         Dim lsContentType        ' ContentType of the binary file (MIME Type)
  201.  
  202.         ' Initialize Fields
  203.         nFieldCount = 0
  204.         ReDim oFields(-1)
  205.  
  206.         ' Read the bytes (binary data) into memory    
  207.         lnByteCount = Request.TotalBytes
  208.         lnBytes = Request.BinaryRead(lnByteCount)
  209.  
  210.         'Get the lnBoundaryBytes
  211.         lnStartPosition = 1
  212.         lnEndPosition = InstrB(lnStartPosition, lnBytes, CStrB(vbCr))
  213.  
  214.         If lnEndPosition >= lnStartPosition Then
  215.             lnBoundaryBytes = MidB(lnBytes, lnStartPosition, lnEndPosition - lnStartPosition)
  216.         End If
  217.  
  218.         lnBoundaryStart = InstrB(1, lnBytes, lnBoundaryBytes)
  219.  
  220.  
  221.         ' Loop until the BoundaryBytes begin with "--"
  222.         Do Until (lnBoundaryStart = InstrB(lnBytes, lnBoundaryBytes & CStrB("--")))
  223.  
  224.             ' All data within this boundary is stored within a local dictionary
  225.             ' to be appended to the class-scope dictionary.
  226.  
  227.             ReDim Preserve oFields(nFieldCount)
  228.             nFieldCount = nFieldCount + 1
  229.  
  230.             Set loField = New clsField
  231.  
  232.             lnDispositionPosition = InstrB(lnBoundaryStart, lnBytes, CStrB("Content-Disposition"))
  233.  
  234.             ' Get an object name
  235.             lnStartPosition = InstrB(lnDispositionPosition, lnBytes, CStrB("name=")) + 6
  236.             lnEndPosition = InstrB(lnStartPosition, lnBytes, CStrB(""""))
  237.             lsFieldName = CStrU(MidB(lnBytes, lnStartPosition, lnEndPosition - lnStartPosition))
  238.             loField.FieldName = lsFieldName
  239.  
  240.             ' Get the location fo the file name.
  241.             lnFileNamePosition = InstrB(lnBoundaryStart, lnBytes, CStrB("filename="))
  242.             lnBoundaryEnd = InstrB(lnEndPosition, lnBytes, lnBoundaryBytes)
  243.  
  244.             'Test if object is a file
  245.             If Not lnFileNamePosition = 0 And lnFileNamePosition < lnBoundaryEnd Then
  246.  
  247.                 ' Parse Filename
  248.                 lnStartPosition = lnFileNamePosition + 10
  249.                 lnEndPosition =  InstrB(lnStartPosition, lnBytes, CStrB(""""))
  250.                 lsFileName = CStrU(MidB(lnBytes,lnStartPosition,lnEndPosition-lnStartPosition))
  251.                 loField.FileName = lsFileName                
  252.  
  253.                 ' Parse Content-Type
  254.                 lnStartPosition = InstrB(lnEndPosition,lnBytes,CStrB("Content-Type:")) + 14
  255.                 lnEndPosition = InstrB(lnStartPosition,lnBytes,CStrB(vbCr))
  256.                 lsContentType = CStrU(MidB(lnBytes,lnStartPosition,lnEndPosition-lnStartPosition))
  257.                 loField.ContentType = lsContentType
  258.  
  259.                 ' Parse Content
  260.                 lnStartPosition = lnEndPosition + 4
  261.                 lnEndPosition = InstrB(lnStartPosition,lnBytes,lnBoundaryBytes)-2
  262.                 lsValue = MidB(lnBytes,lnStartPosition,lnEndPosition-lnStartPosition)
  263.                 loField.BinaryData = lsValue & CStrB(vbNull)
  264.                 loField.Length = LenB(lsValue)
  265.             Else
  266.  
  267.                 ' Parse Content
  268.                 lnStartPosition = InstrB(lnDispositionPosition, lnBytes, CStrB(vbCr)) + 4
  269.                 lnEndPosition = InstrB(lnStartPosition, lnBytes, lnBoundaryBytes) - 2
  270.                 lsValue = CStrU(MidB(lnBytes,lnStartPosition,lnEndPosition-lnStartPosition))
  271.                 loField.Value = lsValue
  272.                 loField.Length = Len(lsValue)
  273.             End If
  274.  
  275.             Set oFields(UBound(oFields)) = loField
  276.  
  277.             'Loop to next object
  278.             lnBoundaryStart = InstrB(lnBoundaryStart + LenB(lnBoundaryBytes), lnBytes, lnBoundaryBytes)
  279.  
  280.             Set loField = Nothing
  281.  
  282.         Loop
  283.  
  284.     End Sub
  285. ' ------------------------------------------------------------------------------
  286.     Private Function CStrU(ByRef psByteString)
  287.         Dim lnLength
  288.         Dim lnPosition
  289.         lnLength = LenB(psByteString)
  290.         For lnPosition = 1 To lnLength
  291.             CStrU = CStrU & Chr(AscB(MidB(psByteString, lnPosition, 1)))
  292.         Next
  293.     End Function
  294. ' ------------------------------------------------------------------------------
  295.     Private Function CStrB(ByRef psUnicodeString)
  296.         Dim lnLength
  297.         Dim lnPosition
  298.         lnLength = Len(psUnicodeString)
  299.         For lnPosition = 1 To lnLength
  300.             CStrB = CStrB & ChrB(AscB(Mid(psUnicodeString, lnPosition, 1)))
  301.         Next
  302.     End Function
  303. ' ------------------------------------------------------------------------------
  304. End Class
  305. ' ------------------------------------------------------------------------------
  306. %>
Sep 13 '07 #1
Share this Question
Share on Google+
1 Reply


jhardman
Expert 2.5K+
P: 3,405
what kind of error was it?

By the way, I'm going to move this to the .NET forum; there are no classes in ASP classic

Jared
Sep 16 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.