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

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!(-:

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.

abzoid,

Thanks a lot!

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

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

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


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

Then on the next page just do your request.


<%=Request("FileName")%>

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.

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!

*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)