473,230 Members | 1,434 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,230 software developers and data experts.

File Upload and Update Contents - Please Help

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

Expand|Select|Wrap|Line Numbers
  1. <%
  2. Server.ScriptTimeout = 5000
  4. Dim Form: Set Form = New ASPForm %><!--#INCLUDE FILE="_upload.asp"--><%
  7. Server.ScriptTimeout = 1000
  8. Form.SizeLimit = &HA00000'10MB
  10. If len(Request.QueryString("UploadID"))>0 then
  11.   Form.UploadID = Request.QueryString("UploadID")'{/b}
  12. End if
  14. Const fsCompleted  = 0
  16. Dim UploadID, PostURL
  17. UploadID = Form.NewUploadID
  19. 'Send this ID as a UploadID QueryString parameter to this script.
  20. PostURL = Request.ServerVariables("SCRIPT_NAME") & "?UploadID=" & UploadID'{/b}
  22. %>
  24. <HTML>
  25. <HEAD>
  26. <TITLE>Testing</TITLE>
  27. </HEAD>
  31. <TABLE>
  32. <BR>
  33. <DIV ALIGN="LEFT">
  34. <FORM NAME="file_upload" METHOD="POST" ENCTYPE="multipart/form-data" OnSubmit="return ProgressBar();" Action="<%=PostURL%>">
  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>
  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>
  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">
  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>
  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>
  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>
  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. <%
  75. If Form.State = fsCompleted Then 'Completed
  77.   'Create destination path+filename for the source file.
  78.   Dim DestinationPath, DestinationFileName
  79.   DestinationPath = Server.mapPath("MOPsUpload")
  80.   DestinationFileName = DestinationPath & "\" & Form("SourceFile").FileName
  83.   'Open recordset to store uploaded data
  84.   Dim RS: Set RS = OpenUploadRS
  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
  99.   Dim Field: For Each Field in Form.Files.Items
  100.   Next
  101.   'Save file to the destination
  102.   Form("SourceFile").SaveAs DestinationFileName
  104.         Response.Write("<FONT FACE=""HELVETICA,HELV,ARIAL"" COLOR=""#FF0000"" SIZE=""2"">Uploaded successfuly.")
  105.     Response.Write("</FONT>")
  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
  115. Function OpenUploadRS()
  116.   Dim RS  : Set RS = CreateObject("ADODB.Recordset")
  118.   'Open dynamic recordset, table Upload
  119.   RS.Open "MOPs", GetConnection, 2, 2
  121.   Set OpenUploadRS = RS
  122. End Function
  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
  130. %>
  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;
  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;
  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. }
  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>
  170. </DIV>
  171. </TD>
  174. </BODY>
  175. </HTML>
Feb 2 '08 #1
2 2866
3,406 Expert 2GB
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.

Feb 4 '08 #2
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

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

Similar topics

by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
by: Jake | last post by:
Hi group, I am trying to build a page that allows uploading My ISP only supports Smartupload I am testing on a small hubbed local network, with PWS Any help is appreciated....
by: bballr | last post by:
What I am trying to do is to take the contents of a very large text file and place it into a LONGTEXT field in a database. I am looking for a solution using the C API to help me handle this. The...
by: Jim Michaels | last post by:
after a file upload, $_FILES is not populated but $_POST is. what's going on here? $_POST=C $_POST=C $_POST=C $_POST=C:\\www\\jimm\\images\\bg1.jpg $_FILES= $_FILES= $_FILES=
by: Vic Spainhower | last post by:
Hello, I am trying to do a FTP file upload which works fine on my localhost but on my ISP server it fails. I can't seem to find where I can go to find the specific cause of the failure. In both...
by: aris1234 | last post by:
hello.. How to upload image file in page update ..?? i have logic like this : if user upload new image then old image must delete and update DB used new name if user not upload new image then...
by: siyaverma | last post by:
i am trying to upload csv file from user's computer to main server the code i am using is if(((isset($_GET)) && ($_GET=="yes")) ) { $typefield = $_GET; echo...
by: amritranjan | last post by:
This is my Jsp code for image upload in database: -----------Upload.jsp---------------- <html> <head> <title>Account Details </title> </head> <body bgproperties="fixed" bgcolor="#CCFFFF">...
by: hotflash | last post by:
Hi All, I found the best pure ASP code to upload a file to either server and/or MS Access Database. It works fine for me however, there is one thing that I don't like and have tried to fix but...
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.