HLRosenberger
asked on
Prompt for folder/file path on client in a WEB app.
How do I Prompt for a folder/file path in WEB app, so that the Prompt appear on the client?
To do what - upload a file?
ASKER
TO save a file on the client machine. That's download, correct?
You cannot force that, it is upto the user to initiate the Save As dialog when they click the link, etc - imagine if you could then lots of nasty sites would be doing it all the time.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Misunderstanding maybe...
ASKER
To be more precise. I'm creating an excel file in the code behind. VB.NET So I guess I need to create it on the server somewhere and then download it to the client. How do I allow the user to pick a folder on their client machine?
That will happen automatically - when the user clicks the link to download
ASKER
ok. So how do I create a link to an excel file I create on the fly?
See the link from Microsoft that I posted above.
ASKER
I'm a novice at this. I added this code the code below. Which is the source file on the server, and which is the path/file on the client? And I need a prompt on the client for where the file is saved. What else do I need? if done correctly, will the browser prompt for where the file is saved?
Dim filename As System.String = "f:\gifts.xlsx"
' set the http content type to "APPLICATION/OCTET-STREAM
Response.ContentType = "APPLICATION/OCTET-STREAM"
' initialize the http content-disposition header to
' indicate a file attachment with the default filename
' "myFile.txt"
Dim disHeader As System.String = "Attachment; Filename=""" & filename & """"
Response.AppendHeader("Con tent-Dispo sition", disHeader)
' transfer the file byte-by-byte to the response object
Dim fileToDownload As New System.IO.FileInfo("c:\gif ts.xlsx")
Response.Flush()
Response.WriteFile(fileToD ownload.Fu llName)
Dim filename As System.String = "f:\gifts.xlsx"
' set the http content type to "APPLICATION/OCTET-STREAM
Response.ContentType = "APPLICATION/OCTET-STREAM"
' initialize the http content-disposition header to
' indicate a file attachment with the default filename
' "myFile.txt"
Dim disHeader As System.String = "Attachment; Filename=""" & filename & """"
Response.AppendHeader("Con
' transfer the file byte-by-byte to the response object
Dim fileToDownload As New System.IO.FileInfo("c:\gif
Response.Flush()
Response.WriteFile(fileToD
You use the name of the file on the server in your code. The browser on the client will prompt for the download location because of the header. The path from the server will not be used on the client side. They get to select the file location on their computer.
ASKER
ok. here's my code. and I'm getting this error:
Error: Sys.WebForms.PageRequestMa nagerParse rErrorExce ption: The message received from the server could not be parsed.
Dim filename As System.String = "c:\gifts.xlsx"
' set the http content type to "APPLICATION/OCTET-STREAM
Response.ContentType = "APPLICATION/OCTET-STREAM"
' initialize the http content-disposition header to
' indicate a file attachment with the default filename
' "myFile.txt"
Dim disHeader As System.String = "Attachment; Filename=" & filename
Response.AppendHeader("Con tent-Dispo sition", disHeader)
' transfer the file byte-by-byte to the response object
Dim fileToDownload As New System.IO.FileInfo("c:\gif ts.xlsx")
Response.Flush()
Response.WriteFile(fileToD ownload.Fu llName)
Error: Sys.WebForms.PageRequestMa
Dim filename As System.String = "c:\gifts.xlsx"
' set the http content type to "APPLICATION/OCTET-STREAM
Response.ContentType = "APPLICATION/OCTET-STREAM"
' initialize the http content-disposition header to
' indicate a file attachment with the default filename
' "myFile.txt"
Dim disHeader As System.String = "Attachment; Filename=" & filename
Response.AppendHeader("Con
' transfer the file byte-by-byte to the response object
Dim fileToDownload As New System.IO.FileInfo("c:\gif
Response.Flush()
Response.WriteFile(fileToD
ASKER
The solution is that I have to use a blank WEB page from which to execute this code.
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for HLRosenberger's comment #a39553552
for the following reason:
This works
Accepted answer: 0 points for HLRosenberger's comment #a39553552
for the following reason:
This works
If anything Dave's answer here
https://www.experts-exchange.com/questions/28258579/Prompt-for-folder-file-path-on-client-in-a-WEB-app.html?anchorAnswerId=39547820#a39547820
should be the accepted answer.
https://www.experts-exchange.com/questions/28258579/Prompt-for-folder-file-path-on-client-in-a-WEB-app.html?anchorAnswerId=39547820#a39547820
should be the accepted answer.
ASKER
GaryC123 - you are correct. My mistake.
ASKER
Thank You!
You're welcome.