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?
LVL 1
HLRosenbergerAsked:
Who is Participating?
 
Dave BaldwinFixer of ProblemsCommented:
Here http://msdn.microsoft.com/en-us/library/aa478985.aspx#aspnet-jspmig-downloadinganduploading_topic6 is a Microsoft article on ASP.NET downloads and some other things.  You have to create a link that has the proper "Content-Disposition" header line.
0
 
GaryCommented:
To do what - upload a file?
0
 
HLRosenbergerAuthor Commented:
TO save a file on the client machine.  That's download, correct?
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
GaryCommented:
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.
0
 
GaryCommented:
Misunderstanding maybe...
0
 
HLRosenbergerAuthor Commented:
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?
0
 
GaryCommented:
That will happen automatically - when the user clicks the link to download
0
 
HLRosenbergerAuthor Commented:
ok. So how do I create a link to an excel file I create on the fly?
0
 
Dave BaldwinFixer of ProblemsCommented:
See the link from Microsoft that I posted above.
0
 
HLRosenbergerAuthor Commented:
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)
0
 
Dave BaldwinFixer of ProblemsCommented:
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.
0
 
HLRosenbergerAuthor Commented:
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)
0
 
HLRosenbergerAuthor Commented:
The solution is that I have to use a blank WEB page from which to execute this code.
0
 
HLRosenbergerAuthor Commented:
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
0
 
GaryCommented:
If anything Dave's answer here
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_28258579.html#a39547820

should be the accepted answer.
0
 
HLRosenbergerAuthor Commented:
GaryC123 - you are correct.  My mistake.
0
 
HLRosenbergerAuthor Commented:
Thank You!
0
 
Dave BaldwinFixer of ProblemsCommented:
You're welcome.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.