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

File Upload and Update Contents - Please Help

P: 85
Hi Master CroCrew,

I found a good PURE ASP that will allow you to upload 10MB file to the server and the file contents such as Network, Author, Title, etc... will insert to MS Access at the same time.

Below is a working script that I used. Let's say after the file is uploaded to the server and a record created with the file contents above to the MS Access (using the script below). If I want to UPDATE that record let's say, change the Author from Mr. A to Mr. B, the new file will overwrite the existing one on the server OK however, how can I modify the RS.AddNew code to make it to UPDATE the MS Access contents such as Author as well? Thank you very much for your OUTSTANDING SUPPORT so far. FYI that the website where the original script located is

http://www.planet-source-code.com/vb...=8225&lngWId=4
Expand|Select|Wrap|Line Numbers
  1. <%
  2. Server.ScriptTimeout = 5000
  3.  
  4. Dim Form: Set Form = New ASPForm %><!--#INCLUDE FILE="_upload.asp"--><%
  5.  
  6.  
  7. Server.ScriptTimeout = 1000
  8. Form.SizeLimit = &HA00000'10MB
  9.  
  10. If len(Request.QueryString("UploadID"))>0 then
  11.   Form.UploadID = Request.QueryString("UploadID")'{/b}
  12. End if
  13.  
  14. Const fsCompleted  = 0
  15.  
  16. Dim UploadID, PostURL
  17. UploadID = Form.NewUploadID
  18.  
  19. 'Send this ID as a UploadID QueryString parameter to this script.
  20. PostURL = Request.ServerVariables("SCRIPT_NAME") & "?UploadID=" & UploadID'{/b}
  21.  
  22. %>
  23.  
  24. <HTML>
  25. <HEAD>
  26. <TITLE>Testing</TITLE>
  27. </HEAD>
  28.  
  29. <BODY BGCOLOR="#FFFFFF">
  30.  
  31. <TABLE>
  32. <BR>
  33. <DIV ALIGN="LEFT">
  34. <FORM NAME="file_upload" METHOD="POST" ENCTYPE="multipart/form-data" OnSubmit="return ProgressBar();" Action="<%=PostURL%>">
  35.  
  36.   &nbsp;&nbsp;&nbsp;&nbsp;<FONT FACE="HELVETICA,HELV,ARIAL" SIZE="2" COLOR="FF0000">** Denotes REQUIRED FIELD.  Please DO NOT press the "Upload File" button twice.</FONT>
  37.      <P></P>
  38.  
  39.     <TR>
  40.         <TD ALIGN="LEFT"><FONT FACE="HELVETICA,HELV,ARIAL" SIZE="2">&nbsp;&nbsp; Network</FONT></FONT><FONT FACE="HELVETICA,HELV,ARIAL" SIZE="1" COLOR="FF0000">&nbsp;&nbsp; ** </FONT></TD>
  41.             <TD>
  42.                                         <SELECT NAME="Network" ID="Network">
  43.                                                     <OPTION VALUE>                                                                                        </OPTION>
  44.                                                     <OPTION VALUE="TEST1"> TEST1                                                                </OPTION>
  45.                              <OPTION VALUE="TEST2"> TEST2                                                                    </OPTION>      
  46.                              </SELECT>
  47.  
  48.                              <FONT FACE="HELVETICA,HELV,ARIAL" SIZE="2">&nbsp;&nbsp; Author</FONT><FONT FACE="HELVETICA,HELV,ARIAL" SIZE="1" COLOR="FF0000">&nbsp;&nbsp; ** </FONT>
  49.                                 <INPUT TYPE="TEXT" NAME="Author" SIZE="40" VALUE="" ID="Author">
  50.  
  51.                                 <FONT FACE="HELVETICA,HELV,ARIAL" SIZE="2">&nbsp;&nbsp; Revision</FONT><FONT FACE="HELVETICA,HELV,ARIAL" SIZE="1" COLOR="FF0000">&nbsp;&nbsp; ** </FONT>
  52.                                 <INPUT TYPE="TEXT" NAME="Revision" SIZE="8" VALUE="" ID="Revision">
  53.              </TD>
  54.     </TR>
  55.  
  56.     <TR>
  57.             <TD ALIGN="LEFT"><FONT FACE="HELVETICA,HELV,ARIAL" SIZE="2">&nbsp;&nbsp; Title</FONT><FONT FACE="HELVETICA,HELV,ARIAL" SIZE="1" COLOR="FF0000">&nbsp; ** </FONT></TD>
  58.             <TD><INPUT TYPE="TEXT" NAME="Title" SIZE="99" VALUE="" ID="Title"></TD>
  59.     </TR>
  60.  
  61.     <TR>
  62.             <TD ALIGN="LEFT"><FONT FACE="HELVETICA,HELV,ARIAL" SIZE="2">&nbsp;&nbsp; File Name</FONT><FONT FACE="HELVETICA,HELV,ARIAL" SIZE="1" COLOR="FF0000">&nbsp;&nbsp; ** </FONT></TD>
  63.             <TD><INPUT TYPE="FILE" NAME="SourceFile" SIZE="86" VALUE="" ID="SourceFile"></TD>
  64.     </TR>
  65.  
  66. </TABLE>
  67.     <CENTER>
  68.     <BR>
  69.     <INPUT CLASS="Table_Blue" TYPE="SUBMIT" VALUE="UPLOAD FILE"> &nbsp;&nbsp;&nbsp;&nbsp;<INPUT CLASS="Table_Blue" TYPE="RESET" VALUE="CLEAR FORM">
  70.     </CENTER>
  71.     <BR>
  72. <CENTER>
  73. <%
  74.  
  75. If Form.State = fsCompleted Then 'Completed
  76.  
  77.   'Create destination path+filename for the source file.
  78.   Dim DestinationPath, DestinationFileName
  79.   DestinationPath = Server.mapPath("MOPsUpload")
  80.   DestinationFileName = DestinationPath & "\" & Form("SourceFile").FileName
  81.  
  82.  
  83.   'Open recordset to store uploaded data
  84.   Dim RS: Set RS = OpenUploadRS
  85.  
  86.   'Store extra info about upload to database
  87.   RS.AddNew
  88.    RS("UploadDT") = Date()
  89.    RS("Network") = Form.Texts.Item("Network")
  90.    RS("Title") = Form.Texts.Item("Title")
  91.    RS("Revision") = Form.Texts.Item("Revision")
  92.    RS("Author") = Form.Texts.Item("Author")
  93.    RS("SourceFileName") = Form("SourceFile").FilePath
  94.    RS("DestFileName") = DestinationFileName
  95.    RS("DataSize") = Form("SourceFile").Length
  96.    '...
  97.   RS.Update
  98.  
  99.   Dim Field: For Each Field in Form.Files.Items
  100.   Next
  101.   'Save file to the destination
  102.   Form("SourceFile").SaveAs DestinationFileName
  103.  
  104.         Response.Write("<FONT FACE=""HELVETICA,HELV,ARIAL"" COLOR=""#FF0000"" SIZE=""2"">Uploaded successfuly.")
  105.     Response.Write("</FONT>")
  106.  
  107. ElseIf Form.State > 10 then
  108.   Const fsSizeLimit = &HD
  109.   Select case Form.State
  110.         case fsSizeLimit: response.write  "<br><Font Color=red>Source form size (" & Form.TotalBytes & "B) exceeds form limit (" & Form.SizeLimit & "B)</Font><br>"
  111.         case else response.write "<br><Font Color=red>Some form error.</Font><br>"
  112.   end Select
  113. End If'Form.State = 0 then
  114.  
  115. Function OpenUploadRS()
  116.   Dim RS  : Set RS = CreateObject("ADODB.Recordset")
  117.  
  118.   'Open dynamic recordset, table Upload
  119.   RS.Open "MOPs", GetConnection, 2, 2
  120.  
  121.   Set OpenUploadRS = RS
  122. End Function
  123.  
  124. Function GetConnection()
  125.     Set Conn = Server.CreateObject("ADODB.Connection")
  126.     Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("YourDatabase.mdb") & "; Jet OLEDB:Database Password=happy"
  127.     set GetConnection = Conn
  128. End function
  129.  
  130. %>
  131.  
  132. </CENTER>
  133. <BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>
  134. </FORM>
  135. <SCRIPT language=javascript>
  136. //Open window with progress bar.
  137. <!--
  138. function ProgressBar(){
  139.   var ProgressURL;
  140.   ProgressURL = 'progress.asp?UploadID=<%=UploadID%>';
  141.   var Network;
  142.   var Revision;
  143.   var Author;
  144.   var Title;
  145.   var SourceFile;
  146.  
  147. Network = file_upload.Network.value;
  148. Revision = file_upload.Revision.value;
  149. Author = file_upload.Author.value;
  150. Title = file_upload.Title.value;
  151. SourceFile = file_upload.SourceFile.value;
  152.  
  153. if (Network.length==0)
  154. {
  155.     alert('Reason:  The "Network" may contain invalid characters or is blank.');
  156.     file_upload.Network.focus();
  157.     return false;
  158. }
  159.  
  160. else
  161. {
  162.   var v = window.open(ProgressURL,'_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=355,height=140');
  163.     return true;
  164. }
  165.   //return;
  166. }
  167. // -->
  168. </SCRIPT>
  169.  
  170. </DIV>
  171. </TD>
  172.  
  173.  
  174. </BODY>
  175. </HTML>
Feb 2 '08 #1
Share this Question
Share on Google+
2 Replies


jhardman
Expert 2.5K+
P: 3,405
Hey hotflash,

Just a reminder, please put your code inside code tags (notice the button marked - #) This makes it much easier to read.

In order to update rather than add new, you need to do two things:

1- open the recordset and make sure you are on the record you want to update. This is the hard part, you will need to either modify the SQL query so that you only return the one record you want (the preferred way), or open all the records and scroll through until you find the record you want to update (takes longer to run, but may be easier for a newbie to code).

2- remove the "RS.addNew" line. This is the easy part, as long as the recordset doesn't add a new record, you will overwrite the previous data.

Let me know if this helps.

Jared
Feb 4 '08 #2

P: 85
Hi Jared,

Thanks for your replying. I have tried both methods you recommended but still have no luck. There are about 30 records on the database. We only need to update the record that is needed. Honestly, this thing is way over my head.

Any other recommendation? There is a link to the code above, wonder if you can try yourself to see if you have any luck or not. The file that I used is
db-file-to-disk. Let's say, once the file is uploaded to the server, and there is an entry in the database. Try to update the Description to see how is it going to work. Thanks once again for your outstanding support.
Feb 7 '08 #3

Post your reply

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