# How can I pass the uploaded file name to parent window using ASP?

**URL:** <https://forum.kirupa.com/t/how-can-i-pass-the-uploaded-file-name-to-parent-window-using-asp/28199>\
**Category:** Uncategorized\
**Created:** [August 11, 2003, 7:19am UTC](https://forum.kirupa.com/t/how-can-i-pass-the-uploaded-file-name-to-parent-window-using-asp/28199 "2003-08-11T07:19:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![SBUH](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@SBUH](https://forum.kirupa.com/u/SBUH)\
**Post date:** [August 11, 2003, 7:19am UTC](https://forum.kirupa.com/t/how-can-i-pass-the-uploaded-file-name-to-parent-window-using-asp/28199/1 "2003-08-11T07:19:21Z")

</div>

I have the function that user can upload a file to the server, and saved it with a new name(added some random number on the original name). but I got to know how can I pass the new name to the form of parent window? PLZ help!(-:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 11, 2003, 12:05pm UTC](https://forum.kirupa.com/t/how-can-i-pass-the-uploaded-file-name-to-parent-window-using-asp/28199/2 "2003-08-11T12:05:07Z")

</div>

If you’ll attach your upload function code page (rename it to a .txt file) I’ll take a look when I get home this evening.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 12, 2003, 5:26am UTC](https://forum.kirupa.com/t/how-can-i-pass-the-uploaded-file-name-to-parent-window-using-asp/28199/3 "2003-08-12T05:26:48Z")

</div>

abzoid,

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 12, 2003, 5:41am UTC](https://forum.kirupa.com/t/how-can-i-pass-the-uploaded-file-name-to-parent-window-using-asp/28199/4 "2003-08-12T05:41:34Z")

</div>

That’s the form page, I need to see the asp code that processes the upload. (uploadexmple.asp)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 12, 2003, 1:27pm UTC](https://forum.kirupa.com/t/how-can-i-pass-the-uploaded-file-name-to-parent-window-using-asp/28199/5 "2003-08-12T13:27:20Z")

</div>

You can’t pass a value back to a parent page that has already been loaded to the users browser. However, you can save the value as an ASP session variable that the next page can retrieve. The added line of code in the function below from your upload code will save the FileName in a Session variable named NewFileName.

I’ll need to see the code for that “next” page in order to show you how to retrieve it where you need it.

Public Sub SaveToDisk(sPath)  
Dim oFS, oFile  
Dim nIndex

If sPath = “” Or FileName = “” Then Exit Sub  
If Mid(sPath, Len(sPath)) \<\> “” Then sPath = sPath & “”

Set oFS = Server.CreateObject(“Scripting.FileSystemObject”)  
If Not oFS.FolderExists(sPath) Then Exit Sub

Set oFile = oFS.CreateTextFile(sPath & FileName, True)

**Session(“NewFileName”) = FileName**

For nIndex = 1 to LenB(FileData)  
oFile.Write Chr(AscB(MidB(FileData,nIndex,1)))  
Next

oFile.Close  
End Sub

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 12, 2003, 2:52pm UTC](https://forum.kirupa.com/t/how-can-i-pass-the-uploaded-file-name-to-parent-window-using-asp/28199/6 "2003-08-12T14:52:44Z")

</div>

If you are still using form elements on the page then you can pass it to the next page using a hidden text box and then request it on the next page.

Like so

```php

<Input type="hidden" name="fileName" value="<%=(FileName)%>">

```

Then on the next page just do your request.

```php

<%=Request("FileName")%>

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 12, 2003, 3:22pm UTC](https://forum.kirupa.com/t/how-can-i-pass-the-uploaded-file-name-to-parent-window-using-asp/28199/7 "2003-08-12T15:22:21Z")

</div>

Digi, the upload form is in a separate popup window so the parent can’t pass the data to the next page since it didn’t yet exist when the page was loaded in the users browser.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 13, 2003, 10:38am UTC](https://forum.kirupa.com/t/how-can-i-pass-the-uploaded-file-name-to-parent-window-using-asp/28199/8 "2003-08-13T10:38:30Z")

</div>

Thanks to you two,

I added random nub. generator before the below line, then I can save it as a new name onto server now.

Set oFile = oFS.CreateTextFile(sPath & FileName, True)

Session(“NewFileName”) = FileName

So how can I retrieve the new name back to parent window? I attached the hinden form of parent window.

Thanks for your help again!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 13, 2003, 12:07pm UTC](https://forum.kirupa.com/t/how-can-i-pass-the-uploaded-file-name-to-parent-window-using-asp/28199/9 "2003-08-13T12:07:10Z")

</div>

> \*Originally posted by SBUH \*  
> **So how can I retrieve the new name back to parent window?**

As I explained in my post just before your last one, you can’t. That page has already loaded in the users browser, there is no way to get that value to that page. That ship has sailed, to coin a phrase.

You need to pick up the Session variable value on the next page, designpage\_flash.asp.

Modify the one line of code on that page to retreive the value from the Session variable (NewFileName) instead of from the URL parameter (image)
