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
270 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Smart quotes being changed on insert 9 50
Grab data from remote page 10 61
Send to Print Preview database record with one click 3 48
INNER JOIN ? 8 41
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now