Link to home
Start Free TrialLog in
Avatar of HLRosenberger
HLRosenbergerFlag for United States of America

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?
Avatar of Gary
Gary
Flag of Ireland image

To do what - upload a file?
Avatar of HLRosenberger

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
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Misunderstanding maybe...
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
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.
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("Content-Disposition", disHeader)

                ' transfer the file byte-by-byte to the response object
                Dim fileToDownload As New System.IO.FileInfo("c:\gifts.xlsx")
                Response.Flush()
                Response.WriteFile(fileToDownload.FullName)
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.
ok.  here's my code.  and I'm getting this error:



Error: Sys.WebForms.PageRequestManagerParserErrorException: 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("Content-Disposition", disHeader)

                ' transfer the file byte-by-byte to the response object
                Dim fileToDownload As New System.IO.FileInfo("c:\gifts.xlsx")
                Response.Flush()
                Response.WriteFile(fileToDownload.FullName)
The solution is that I have to use a blank WEB page from which to execute this code.
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
GaryC123 - you are correct.  My mistake.
Thank You!
You're welcome.