- Apr 17, 2003
- 21
- 0
- 0
Need help with this. I am trying to have one script upload a file then add a record to the database and one of the calls is a variable. I want the formname (which is actually filename) to be called from the uploaded file. Here is the code. Any help would be GREATLY appreicated. Also I don't have money to buy a product so please don't suggest that.
First the upload doesn't work. The MBRequest(file1).Save isn't supported in this manner. I know you can use .save to upload a file.
second I can't figure out if the call for FORMNAME would work.
<%@ LANGUAGE=VBSCRIPT %>
<%Option Explicit%>
<%
Dim DB_CONNECTIONSTRING
Dim objRecordset
Dim Added
Dim ServerPath
Dim strPath
Dim MBRequest
%>
<!--#include file="adovbs.inc"-->
<%
DB_CONNECTIONSTRING = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.Mappath("FORMS.mdb") & ";"
Set objRecordset = Server.CreateObject("ADODB.Recordset")
objRecordset.Open "Forms", DB_CONNECTIONSTRING, adOpenStatic, adLockPessimistic, adCmdTable
If Request.Form("btnAdd") = "Add Form" Then
Serverpath = "c:\inetpub\wwwroot\forms"
strPath = Serverpath & "\" & Request.Form("selLocation")
set MBRequest = GetObject( strPath )
' If MBRequest ("submit") = "upload" then
' Response.Write "You Uploaded: " & MBRequest("File1").Path & MBRequest("File1").FileName & "
" & vbNewLine
' Response.Write "The Extension Is: " & MBRequest("File1").Extension & "
" & vbNewLine
' Response.Write "The MIME/ContentType Is: " & MBRequest("File1").ContentType
' -- Save the uploaded file to the directory this ASP script resides in --
MBRequest("File1").Save
' -- Next part --
objRecordset.AddNew
'-- Add records to database from form --
objRecordset.Fields("DATEOFENTRY") = Request.Form("txtDateOfEntry")
objRecordset.Fields("FORMTITLE") = Request.Form("txtFormTitle")
objRecordset.Fields("FORMNAME") = MBRequest("File1").FileName & MBRequest("File1").Extension HERE IS MY CALL.
objRecordset.Fields("FILETYPE") = Request.Form("selFileType")
objRecordset.Fields("LOCATION") = Request.Form("selLocation")
objRecordset.Fields("COMMENTS") = Request.Form("txtComments")
objRecordset.Fields("ENTEREDBY") = Request.Form("txtEnteredBy")
objRecordset.Update
Added = "True"
' End
End If
objRecordset.Close
Set objRecordset = Nothing
set MBRequest = Nothing
If Added = "True" Then
Response.Redirect ("formlist5.asp")
End If
%>
<html><title>Add Form</title>
<body>
<center>
<font size="4"><strong>Add New Form or Document</strong></font>
ALL Fields <strong>MUST</strong> be filled out.
<form method="post" action="AddForm.asp" enctype="multipart/form-data">
<table border="1" cellpadding="2" cellspacing="1" width="75%">
<tr>
<td><strong>Form/Document Title: </strong></td>
<td><input type="text" name="txtFormTitle" size="35"></td>
</tr>
<tr>
<td><strong>File : </strong></td>
<td><input type="file" name="File1" size="35"></td>
</tr>
<tr>
<td><strong>File Type : </strong></td>
<td><select name="selFileType">
<option value="Word">Word</option>
<option value="Excel">Excel</option>
<option value="Web">Web Based</option>
<option value="PDF">Acrobat Reader</option>
<option value="PowerPoint">PowerPoint</option>
<option value="Publisher">Publisher</option>
<option value="Other">Other</option>
</select></td>
</tr>
<tr>
<td> <strong>Location</strong> file will reside (who will have access
to view said file): </td>
<td> <select name="selLocation">
<option value="Employee">Employee</option>
<option value="HR">HR</option>
<option value="Training">Training</option>
<option value="Provider">Provider</option>
<option value="Managers">Managers</option>
<option value="Printing">Printing</option>
</select></td>
</tr>
<tr>
<td><strong>Comments :</strong></td>
<td><textarea name="txtComments" cols="40" rows="5"></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="hidden" name="txtEnteredBy" size="35" value="<% = request.servervariables("logon_user") %>">
<input name="txtDateOfEntry" type="hidden" value="<% = Date %>" size="10" maxlength="10"></td>
</tr>
</table>
<p>
<input type="submit" name="btnAdd" value="Add Form"><input type="Reset" name="btnReset" value="Clear">
</form>
</center>
</body>
</html>
First the upload doesn't work. The MBRequest(file1).Save isn't supported in this manner. I know you can use .save to upload a file.
second I can't figure out if the call for FORMNAME would work.
<%@ LANGUAGE=VBSCRIPT %>
<%Option Explicit%>
<%
Dim DB_CONNECTIONSTRING
Dim objRecordset
Dim Added
Dim ServerPath
Dim strPath
Dim MBRequest
%>
<!--#include file="adovbs.inc"-->
<%
DB_CONNECTIONSTRING = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.Mappath("FORMS.mdb") & ";"
Set objRecordset = Server.CreateObject("ADODB.Recordset")
objRecordset.Open "Forms", DB_CONNECTIONSTRING, adOpenStatic, adLockPessimistic, adCmdTable
If Request.Form("btnAdd") = "Add Form" Then
Serverpath = "c:\inetpub\wwwroot\forms"
strPath = Serverpath & "\" & Request.Form("selLocation")
set MBRequest = GetObject( strPath )
' If MBRequest ("submit") = "upload" then
' Response.Write "You Uploaded: " & MBRequest("File1").Path & MBRequest("File1").FileName & "
" & vbNewLine
' Response.Write "The Extension Is: " & MBRequest("File1").Extension & "
" & vbNewLine
' Response.Write "The MIME/ContentType Is: " & MBRequest("File1").ContentType
' -- Save the uploaded file to the directory this ASP script resides in --
MBRequest("File1").Save
' -- Next part --
objRecordset.AddNew
'-- Add records to database from form --
objRecordset.Fields("DATEOFENTRY") = Request.Form("txtDateOfEntry")
objRecordset.Fields("FORMTITLE") = Request.Form("txtFormTitle")
objRecordset.Fields("FORMNAME") = MBRequest("File1").FileName & MBRequest("File1").Extension HERE IS MY CALL.
objRecordset.Fields("FILETYPE") = Request.Form("selFileType")
objRecordset.Fields("LOCATION") = Request.Form("selLocation")
objRecordset.Fields("COMMENTS") = Request.Form("txtComments")
objRecordset.Fields("ENTEREDBY") = Request.Form("txtEnteredBy")
objRecordset.Update
Added = "True"
' End
End If
objRecordset.Close
Set objRecordset = Nothing
set MBRequest = Nothing
If Added = "True" Then
Response.Redirect ("formlist5.asp")
End If
%>
<html><title>Add Form</title>
<body>
<center>
<font size="4"><strong>Add New Form or Document</strong></font>
ALL Fields <strong>MUST</strong> be filled out.
<form method="post" action="AddForm.asp" enctype="multipart/form-data">
<table border="1" cellpadding="2" cellspacing="1" width="75%">
<tr>
<td><strong>Form/Document Title: </strong></td>
<td><input type="text" name="txtFormTitle" size="35"></td>
</tr>
<tr>
<td><strong>File : </strong></td>
<td><input type="file" name="File1" size="35"></td>
</tr>
<tr>
<td><strong>File Type : </strong></td>
<td><select name="selFileType">
<option value="Word">Word</option>
<option value="Excel">Excel</option>
<option value="Web">Web Based</option>
<option value="PDF">Acrobat Reader</option>
<option value="PowerPoint">PowerPoint</option>
<option value="Publisher">Publisher</option>
<option value="Other">Other</option>
</select></td>
</tr>
<tr>
<td> <strong>Location</strong> file will reside (who will have access
to view said file): </td>
<td> <select name="selLocation">
<option value="Employee">Employee</option>
<option value="HR">HR</option>
<option value="Training">Training</option>
<option value="Provider">Provider</option>
<option value="Managers">Managers</option>
<option value="Printing">Printing</option>
</select></td>
</tr>
<tr>
<td><strong>Comments :</strong></td>
<td><textarea name="txtComments" cols="40" rows="5"></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="hidden" name="txtEnteredBy" size="35" value="<% = request.servervariables("logon_user") %>">
<input name="txtDateOfEntry" type="hidden" value="<% = Date %>" size="10" maxlength="10"></td>
</tr>
</table>
<p>
<input type="submit" name="btnAdd" value="Add Form"><input type="Reset" name="btnReset" value="Clear">
</form>
</center>
</body>
</html>