Error 457

Results 1 to 2 of 2

Thread: Error 457

  1. #1
    Join Date
    Dec 1969

    Default Error 457

    I&#039;m using the pure ASP upload program in conjunction with a set of commands that adds information into a database...although I continually get this error:<BR><BR>Microsoft VBScript runtime (0x800A01C9)<BR>This key is already associated with an element of this collection<BR>filepost.asp, line 95<BR><BR>any ideas? Here&#039;s the code<BR><BR><BR> &#060;!-- METADATA TYPE="typelib";<BR>FILE="C:program filescommon filessystemADOmsado15.dll" --&#062;<BR>&#060;%<BR><BR>&#039;Adjust this depending on the size of the files you&#039;ll<BR>&#039;be expecting; longer timeout for larger files!<BR>Server.ScriptTimeout = 5400<BR><BR>Const ForWriting = 2<BR>Const TristateTrue = -1<BR>CrLf = Chr(13) & Chr(10)<BR><BR>&#039;This function retreives a field&#039;s name<BR>Function GetFieldName(infoStr)<BR> sPos = InStr(infoStr, "name=")<BR> EndPos = InStr(sPos + 6, infoStr, Chr(34) & ";")<BR> If EndPos = 0 Then<BR> EndPos = inStr(sPos + 6, infoStr, Chr(34))<BR> End If<BR> GetFieldName = Mid(infoStr, sPos + 6, endPos - _<BR> (sPos + 6))<BR>End Function<BR>&#039;This function retreives a file field&#039;s filename<BR>Function GetFileName(infoStr)<BR> sPos = InStr(infoStr, "filename=")<BR> EndPos = InStr(infoStr, Chr(34) & CrLf)<BR> GetFileName = Mid(infoStr, sPos + 10, EndPos - _<BR> (sPos + 10))<BR>End Function<BR><BR>&#039;This function retreives a file field&#039;s MIME type<BR>Function GetFileType(infoStr)<BR> sPos = InStr(infoStr, "Content-Type: ")<BR> GetFileType = Mid(infoStr, sPos + 14)<BR>End Function<BR><BR>&#039;Yank the file (and anything else) that was posted<BR>PostData = ""<BR>Dim biData<BR>biData = Request.BinaryRead(Request.TotalBytes)<BR>&#039;Ca reful! It&#039;s binary! So, let&#039;s change it into<BR>&#039;something a bit more manageable.<BR>For nIndex = 1 to LenB(biData)<BR> PostData = PostData & Chr(AscB(MidB(biData,nIndex,1)))<BR>Next<BR><BR>&# 039;Having used BinaryRead, the myRequest collection is<BR>&#039;no longer available to us. So, we have to parse the<BR>&#039;request variables ourselves!<BR>&#039;First, let&#039;s find that encoding type!<BR>ContentType = Request.ServerVariables( _<BR> "HTTP_CONTENT_TYPE")<BR>ctArray = Split(ContentType, ";")<BR>&#039;File posts only work well when the encoding is <BR>&#039;"multipart/form-data", so let&#039;s check for that!<BR>If Trim(ctArray(0)) = "multipart/form-data" Then<BR> ErrMsg = ""<BR> &#039; grab the form boundary...<BR> bArray = Split(Trim(ctArray(1)), "=")<BR> Boundary = Trim(bArray(1))<BR> &#039;Now use that to split up all the variables!<BR> FormData = Split(PostData, Boundary)<BR> &#039;Extract the information for each variable and its data<BR> Dim myRequest, myRequestFiles(9, 3) <BR> Set myRequest = CreateObject("Scripting.Dictionary")<BR> FileCount = 0<BR> For x = 0 to UBound(FormData)<BR> &#039;Two CrLfs mark the end of the information about<BR> &#039;this field; everything after that is the value<BR> InfoEnd = InStr(FormData(x), CrLf & CrLf)<BR> If InfoEnd &#062; 0 Then<BR> &#039;Get info for this field, minus stuff at the end<BR> varInfo = Mid(FormData(x), 3, InfoEnd - 3)<BR> &#039;Get value for this field, being sure to skip<BR> &#039;CrLf pairs at the start and the CrLf at the end<BR> varValue = Mid(FormData(x), InfoEnd + 4, _<BR> Len(FormData(x)) - InfoEnd - 7)<BR> &#039;Is this a file?<BR> If (InStr(varInfo, "filename=") &#062; 0) Then<BR> &#039;Place it into our files array<BR> &#039;(While this supports more than one file<BR> &#039;uploaded at a time we only consider the<BR> &#039;single file case in this example)<BR> myRequestFiles(FileCount, 0) = GetFieldName( _<BR> varInfo)<BR> myRequestFiles(FileCount, 1) = varValue<BR> myRequestFiles(FileCount, 2) = GetFileName( _<BR> varInfo)<BR> myRequestFiles(FileCount, 3) = GetFileType( _<BR> varInfo)<BR> FileCount = FileCount + 1<BR> Else<BR> &#039;It&#039;s a regular field<BR> myRequest.add GetFieldName(varInfo), varValue<BR> End If<BR> End If<BR> Next<BR>Else<BR> ErrMsg = "Wrong encoding type!"<BR>End If <BR><BR>If NOT myRequest("filename") = "nofile" Then<BR><BR>&#039;Save the actual posted file<BR>&#039;If supporting more than one file, turn this into a loop!<BR><BR>Set lf = server.createObject("Scripting.FileSystemObject")< BR>If myRequest("filename") = "original" Then<BR> &#039;Use the filename that came with the file<BR> &#039;At this point, you need to determine what sort of<BR> &#039;client sent the file. Macintoshes only send the file<BR> &#039;name, with no path information, while Windows clients<BR> &#039;send the entire path of the file that was selected<BR> BrowserType = UCase(Request.ServerVariables( _<BR> "HTTP_USER_AGENT"))<BR> If (InStr(BrowserType, "WIN") &#062; 0) Then<BR> &#039;It&#039;s Windows; yank the filename off the end!<BR> sPos = InStrRev(myRequestFiles(0, 2), "\")<BR> fName = Mid(myRequestFiles(0, 2), sPos + 1)<BR> End If<BR> If (InStr(BrowserType, "MAC") &#062; 0) Then<BR> &#039;It&#039;s a Mac. Simple.<BR> &#039;(Mac filenames can contain characters that are <BR> &#039;illegal under Windows, so look out for that!)<BR> fName = myRequestFiles(0, 2)<BR> End If<BR> &#039;If your upload path is different, set that here<BR> FilePath = "/files/" & fName<BR>Else<BR> &#039;Use the user-specified filename instead<BR> &#039;If your upload path is different, set that here<BR> FilePath = "/files/" & myRequest("userSpecifiedName")<BR>End If<BR>SavePath = Server.MapPath(FilePath)<BR>Set SaveFile = lf.CreateTextFile(SavePath, True)<BR>SaveFile.Write(myRequestFiles(0, 1))<BR>SaveFile.Close<BR>End If<BR>&#039;IIS may hang if you don&#039;t explicitly return SOMETHING.<BR>&#039;So, redirect to another page or provide some kind of<BR>&#039;feedback below...<BR><BR>%&#062;<BR><BR>&#060;%<BR>If Session("Auth") = "none" Or Session("Auth") = "read" Then<BR> Response.Redirect("logon.asp")<BR>End If<BR><BR>If NOT Len(myRequest("title")) and NOT Len(myRequest("adddate")) and myRequest("addjournal") = "Choose a Journal" and myRequest("addauthor") = "Choose an Author" Then<BR> Response.Redirect("add.asp")<BR>End If<BR><BR>&#039;declare variables<BR>Dim strCnxn, iArraySize, filearray<BR><BR><BR>strCnxn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _<BR>"Data Source=c:faqUSC.mdb;"<BR>&#039;"User ID=; Password=;"<BR><BR>Set Cnxn = Server.CreateObject("ADODB.Connection")<BR>Cnxn.Op en strCnxn<BR><BR>Set rsPaper = Server.Createobject("ADODB.Recordset")<BR><BR>rsPa per.ActiveConnection = Cnxn<BR>rsPaper.CursorLocation = adUseServer<BR>rsPaper.CursorType = adOpenStatic<BR>rsPaper.LockType = adLockOptimistic<BR>rsPaper.Source = "material"<BR>rsPaper.Open<BR><BR><BR>rsPaper.AddN ew<BR><BR> If Len(myRequest("title")) Then<BR> rsPaper.Fields("Title") = myRequest("title")<BR> Else<BR> rsPaper.Fields("Title") = "Not Available" <BR> End If<BR><BR> If Len(myRequest("addauthor")) and Not myRequest("addauthor") = "Choose an Author" Then<BR> rsPaper.Fields("Author") = myRequest("addauthor")<BR> Else<BR> rsPaper.Fields("Author") = "Not Available" <BR> End If<BR><BR> If Len(myRequest("addjournal")) and Not myRequest("addjournal") = "Choose a Journal" Then<BR> rsPaper.Fields("Journal") = myRequest("addjournal")<BR> Else<BR> rsPaper.Fields("Journal") = "Not Available" <BR> End If<BR> <BR> If Len(myRequest("adddate")) Then<BR> rsPaper.Fields("Written") = myRequest("adddate")<BR> Else<BR> rsPaper.Fields("Written") = "01/01/0001" <BR> End If<BR><BR> If Len(myRequest("addkeyword")) Then<BR> rsPaper.Fields("Keywords") = myRequest("addkeyword")<BR> Else<BR> rsPaper.Fields("Keywords") = "Not Available" <BR> End If<BR> <BR> rsPaper.Fields("Example") = fName<BR><BR>rsPaper.Update<BR>rsPaper.Close<BR><B R>Response.Redirect("add.asp")<BR>%&#062;<BR>

  2. #2
    Join Date
    Dec 1969

    Default what's on line 95?

    no one is going to read all of that, sorry

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts