Solved

How do I get the name of my attachments, into a STRING, so I can save them in the database

Posted on 2006-07-11
20
274 Views
Last Modified: 2006-11-18
I have a form which has a pop up window, called "browse.asp" because here the users choose their attachments which get updated in a FOLDER called "Attachments" on my web server.
That part works.
The problem is that because of my programming when I click Attach Files the original page called "submit.asp" comes up in the pop-up window.  I would like the pop up window to close by itself, but if I do onClick = "window.close()" from the submit button called "ATTACH FILES" then my files do not get saved in the "Attachments" folder... That's why I created another button called "CLOSE WINDOW"

But this doesn't look very good, having the submit.asp page appear in the little pop up window.  Can you help me with that?

Secondly, I also need the name of the files being attached to be saved in a string or array, so that I can display them on the SUBMIT.ASP page, and when I click SUBMIT to save them in the database(that part works)

************Here is my code for browse.asp****************
<FORM METHOD="POST"  ACTION="submit.asp" ENCTYPE="multipart/form-data" id = "mainform" name = "mainform">

<table border="0" cellspacing="2" cellpadding="2" align="center" style = "background:#CBCBCC; border-style: inset">
  <tr>
    <td>      
      <font face="Arial" size="2">Use the "Browse" button to find the files you would like to attach.<BR><br><br>
      </font>
                    <INPUT TYPE="FILE" NAME="attach1" VALUE="" size = "40">
                <INPUT TYPE="HIDDEN" NAME="doc1">
                  <br><br>
                  <INPUT TYPE="submit" value="Attach File" name = "fileBtn" id = "fileBtn" onClick = "window.close()" >
                  <input type = "button" value = "Close Window" name = "close" onClick = "closeWin()" >
<%response.write(doc1) %><br>
      </td>
  </tr>
</table>
<script type="text/javascript">
<!--
document.mainform.doc1.value += document.mainform.attach1.value;

function closeWin() {
      window.close()
}
//-->
</script>



************Here is my code for submit.asp****************
<%@ Language=VBScript %>
<!-- #include file="freeASPUpload.asp" -->
<FORM METHOD="POST"  ACTION="Proposals.asp" onSubmit="return validate(this)" name = "ProposalsForm" ENCTYPE="multipart/form-data" >
<input type = "button" value = "Attach File" name = "attachBtn" id = "attachBtn" onClick = "browseWindow();"  style = "background:#0D6B9C; font-weight:bold; color:#FFFFFF;">      
      <br>                        
      <INPUT type="submit" value="Submit" name="submit" style = "background:#0D6B9C; font-weight:bold; color:#FFFFFF;"><br><br><br>      <INPUT TYPE="HIDDEN" NAME="file1">

<script type="text/javascript">
function browseWindow(){
      window.open("browse.asp","NewWindow","menu=no,width=400,height=200")
}
//-->
</script>

<%
'angie H -- the files are uploaded to folder "angie" and saved there before sent as attachments through the email
Set Upload = New FreeASPUpload
Attachment = Upload.Form("attach1")
Upload.Save("\\opic-intranetdv\wwwroot$\angie\Attachments\")
                  
'Get the Full Path
dim FilePath1
FilePath1 = Upload.Form("doc1")
response.write FilePath1
response.write("<br>")

'Transform the FULL PATH into the FILE NAME only
Set fs=Server.CreateObject("Scripting.FileSystemObject")
      
'fileName1 = rs("ProposalId") & "_" & fs.GetFileName(FilePath1)
fileName1 = fs.GetFileName(FilePath1)
response.write fileName1
response.write("<br>")

set fs=nothing
%>
</FORM>


The last form is proposals.asp, and that puts the form data into the database.  I need the file names of the attachments in the database so that's part of the reason I need them saved in a string or array....
0
Comment
Question by:Gemini532
  • 11
  • 9
20 Comments
 
LVL 31

Expert Comment

by:alorentz
ID: 17087113
browse.asp should pst ack to itself, not back to submit.asp.  The file upload code should be in browse.asp, not submit.asp.

And then use the buttons "Save and Close"  and "Save and Attach Another"...as we discussed.  Two options to submit...one just saves and closes the form, and the other saves and allows for additional upload.
0
 
LVL 31

Expert Comment

by:alorentz
ID: 17087119
And, for proposals.asp, you would just save the filenames in a session variable, each time you upload a new file.
0
 
LVL 31

Expert Comment

by:alorentz
ID: 17090240
Or, I guess you could post the form to the parent, and let submit.asp do the upload: target

<FORM METHOD="POST"  target="_parent" ACTION="Proposals.asp" onSubmit="return validate(this)" name = "ProposalsForm" ENCTYPE="multipart/form-data" >
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:Gemini532
ID: 17090262
My "Save and Close"  button does NOT work.  The "Save and Attach Another" button works....
I think the problem might be the window.close(), it might be closing before saving the file...

<INPUT TYPE="submit" value="Save and Close" name = "closeBtn" id = "closeBtn" onClick = "closeWin()">

<input type = "submit" value = "Save and Attach Another" name = "attachBtn"  id = "attachBtn" >

<script type="text/javascript">
<!--
function closeWin() {
      window.close()
}
//-->
</script>
0
 

Author Comment

by:Gemini532
ID: 17090300
Should I use window.opener to get the value session variable which will hold the FileNames...
0
 
LVL 31

Accepted Solution

by:
alorentz earned 500 total points
ID: 17090383
<INPUT TYPE="submit" value="Save and Close" name = "closeBtn" id = "closeBtn" onClick = "closeWin()">
<input type = "submit" value = "Save and Attach Another" name = "attachBtn"  id = "attachBtn" >

<%
if request("closeBtn") <> "" then
%>
<script type="text/javascript">
     window.close()
</script>
<%
end if
%>
0
 
LVL 31

Expert Comment

by:alorentz
ID: 17090393
Whoops....TAKE OUT THE ONCLICK EVENT IN THE "Save and Close" button...you don't need it.
0
 

Author Comment

by:Gemini532
ID: 17110822
How do I create a session variable..
I tried this code, but it doesn't work:

Session("fileName") = Request.Form("attach1")
Response.Write("session " & Session("fileName"))

It's not giving me the value of the URL Session("fileName") is blank when I do Response.Write("session " & Session("fileName")) on browse.asp

Also I had to change
your code:
if request("closeBtn") <> "" then
to
if Upload.Form("closeBtn") <> "" then
Because it was giving me an error
0
 

Author Comment

by:Gemini532
ID: 17110848
I figured I save the path in a session variable then get the file name and then add the proposalId to the file name so it will look like this, and then save it in the folder....Becasue otherwise, what if 2 people submit a file with the same name, the original will be overwritten, am I right?

23_Readme.txt
0
 

Author Comment

by:Gemini532
ID: 17110872
That was my first idea, but in order to that I've got to get the proposallId from the database in browse.asp, and that's not possible...

Unless I add a unique number to the filename and then I save that unique number in the database as the proposal ID, instead of having the database generate a unique number for each record on its own...

What do you think?
0
 
LVL 31

Expert Comment

by:alorentz
ID: 17110914
Probly cuz' you have to use the upload form:

Session("fileName") = Upload.Form("attach1")
0
 

Author Comment

by:Gemini532
ID: 17110988
No luck   :(    it still doesn't show anything when I do Response.Write("session " & Session("fileName"))
0
 
LVL 31

Expert Comment

by:alorentz
ID: 17111092
Hard to tell what's going or what you've done...been 2 days since you posted.  

So, don't know what code you have, nor your process logic of how the pages are workgin.
0
 

Author Comment

by:Gemini532
ID: 17111271
Sorry about that, I had to work on another project.  It was an emergency...

This is my code in browse.asp, the session variable called Session("fileName") is not working      :(

<FORM METHOD="POST"  ACTION="browse.asp" ENCTYPE="multipart/form-data" id = "mainform" name = "mainform">
<table border="0" cellspacing="2" cellpadding="2" align="center" style = "background:#CBCBCC; border-style: inset">
  <tr>
    <td>      
      <font face="Arial" size="2">Use the "Browse" button to find the files you would like to attach.<BR><br><br>
      </font>
                    <INPUT TYPE="FILE" NAME="attach1" VALUE="" size = "80">
                <INPUT TYPE="HIDDEN" NAME="doc1">
                  <br><br>
                  <INPUT TYPE="submit" value="Save and Close" name = "closeBtn" id = "closeBtn">
                  <input type = "submit" value = "Save and Attach Another" name = "attachBtn"  id = "attachBtn" >
                                    
<%response.write(doc1) %><br>
      </td>
  </tr>
</table>
<%
'angie H -- the files are uploaded to folder "angie" and saved there before sent as attachments through the email
Set Upload = New FreeASPUpload
Attachment = Upload.Form("attach1")
Upload.Save("\\opic-intranetdv\wwwroot$\angie\Attachments\")

Session("fileName") = Upload.Form("attach1")
Response.Write("session " & Session("fileName"))
if Upload.Form("closeBtn") <> "" then

%>
<script type="text/javascript">
     window.close()
</script>
<%
end if
%>
</form>


I didn't make changes 2 my other 2 pages....submit.asp and proposals.asp
except that I changed the form in submit.asp from

<FORM METHOD="POST"  ACTION="Proposals.asp" onSubmit="return validate(this)" name = "ProposalsForm" ENCTYPE="multipart/form-data" >
to this
<FORM METHOD="POST"  ACTION="Proposals.asp" onSubmit="return validate(this)" name = "ProposalsForm" >

0
 
LVL 31

Expert Comment

by:alorentz
ID: 17111501
What about:


Response.Write("session " & Upload.Form("attach1"))
0
 

Author Comment

by:Gemini532
ID: 17111787
But that won't help me when I try to get this data from the submit.asp or the proposals.asp pages...
0
 

Author Comment

by:Gemini532
ID: 17111796
I need a session variable to save the data so I can call it from the proposals page and save the name of the files in the database...
0
 
LVL 31

Expert Comment

by:alorentz
ID: 17111824
I'm debugging DAMNIT!

I'm not here to go back and forth with you...
0
 

Author Comment

by:Gemini532
ID: 17111842
I'm sorry
I did it
Response.Write("session " & Upload.Form("attach1"))
but I got no value!  
0
 

Author Comment

by:Gemini532
ID: 17111921
I FIGURED IT OUT!  I saved the file variable into a hidden textbox and then saved the hidden variable into the session variable...
!!!!!!!THANKS!!!!!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Select distinct 25 115
Server Timeout with Loop 6 52
Jquery Check against database on select from auto fill not working in all browsers 5 41
innerHTML 7 34
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question