I am using Fileupload control to upload file. I am displaying the selected file icon(with achor tag) with file name. if click the icon i want to open the selected file in a new window.
How to take the selected file path from the fileupload control.
Nathiya,
Do you want to open the file BEFORE it is uploaded to the server?
If the file was already uploaded to the server, then you know the file's path since you passed it to the FileUpload1.SaveAs() method.
If you want it before (e.g. someone clicked on the browse button and choose a file but did not upload it to the server) - Then this is not possible as the file is still on the user's local computer (you can't show files that are on the user's computer, only files that are on your server).
What i came to know from the search is it is not possible
As it leads to privacy breach and security breach
Please check this Get Full File path
FileUpload1.FileName will give you the name of a file on a client.
EDIT : As per the comment. You should first upload the file to your server. Then use the path (the url to the file) to set as the href value of an achor tag.
Related
Is there a way to get the select file dialog box open and putting the location of the file into a textbox without ever uploading the file?
ETA I'm using VB.NET in a web page. By using the asp:fileupload tag I can get the file location
_fudFileLocation.PostedFile.FileName_
But how do I prevent the file from being uploaded at all. We don't need it, just the file location. (The files are on a shared drive so if it's M:\documents\todayslunch.pdf for person A, it's the same for person B.)
You do not get access to the full filepath in the browser because of security.
If this was possible, one could get the full layout of the computer of anyone going to any website.
System.Web.HttpPostedFile.FileName gets the fully qualified name of the file on the client which includes the directory path.
I need to give an option to user in jsp to choose a folder where he can save/download a file. Please help me on the same.
the text input="file" will give the file chooser but i need the directory chooser
HTTP doesn't allow you to specify (server side) where a file is downloaded to - this is not a jsp specific thing.
If you need to this then you'd need to provide an embedable application (javascript, java, flash, vbscript...) which is allowed to operate outside the browser sandbox and implements its own network client for retrieving the file. Which is far from an ideal solution.
You can force the download to use a specific name via the content disposition header.
the text input="file" will give the file chooser
..but that's for uploads - not downloads.
You can't set folder location at client machine of downloaded file using JSP/Servlet. If you want to add folder chooser feature then you have to develop an applet. You may use JFileChooser to allow user to select a folder and java.net.URL and java.net.URLConnection to download a file.
Most browsers will automatically download a file that the browser doesn't render, so it's just a link...! For example, if it's a zip file, just add it as any old "a link" in your code. When the user clicks , the download/save dialog will be launched ....
The "save/download" feature is a client issue -remember the web developers job is to provide content- it's the browser that decides how to deal with the content.
The key is the Content-Disposition header. Its value has to be set to attachment to force a Save As dialogue. You can do this job in a servlet. Just let your link URL point to a file servlet like so
download filename.ext
Then, in the file servlet, which is for the above example to be mapped on an URL pattern of /fileservlet/*, do the following:
String filename = URLDecoder.decode(request.getPathInfo().substring(1), "UTF-8");
response.setHeader("Content-Type", getServletContext().getMimeType(filename));
response.setHeader("Content-Disposition", "attachment;filename=\"" + filename + "\"");
// Now get an InputStream of the file and write it to OutputStream of response.
See also:
Simplest way to serve static data from outside the application server in a Java web application
I have saved images using File upload control in asp.net now i want fetch its path from database and display into file upload control please help me out
You will have to display image in image control using Server.MapPath("~/SomeDir/image.jpg")
Why would you want the server file path to appear in the file upload control? If you think about it, it makes no sense. The path that comes back would be relevant to the server, not the user so chances are the location would not exist on the users machine. If you really need to display the server location for any reason just stick it in a label.
I am creating an excel report in vb.net using the office interop. When the report is completed I am saving the excel file on the C drive. The users have asked to save file anywhere they want not just the c drive. Can someone give me some code to popup an opend file dialog in asp.net?
I want the dialog to popup in a saveAs in ASP.NET. I know how to do it in win forms, but I am creating an excel report in asp.net and calling the worksheet objects SaveAs property that excepts a fileName. So right now I just hardcode a file name in there. The users want to choose a file location
I think what you want is actually rather simple.
You can't save a file to the user's computer due to security restrictions (would you want a website saving a file to your computer?)
What you need to do is:
Complete report
Save report file to location on server, IE (.../myWebsite/files/GUID/myReport.rpt)
Display link on next screen pointing to the report file
Doing this the user can right-click and save the file to wherever they want on their computer.
You can clean up these files on whatever schedule you would like.
Assuming you are actually talking about a desktop, winforms app then you can use the built in FileSaveDialog.
Official documentation is here:
http://msdn.microsoft.com/en-us/library/system.windows.forms.savefiledialog.aspx
but there are tons of tutorials explaining it out there:
http://www.google.co.uk/search?q=vb.net+savefiledialog
You can server files with the Open / Save dialog by using Response.TransmitFile().
The user is then presented with a save as dialog where they can choose the filename and the location on their computer.
You normally do this inside a HttpHandler. A simple one is described here:
http://blogs.msdn.com/petel/archive/2005/12/01/499189.aspx
If you know the local path and file name of the file you want the end user to upload (via browser). Then is it possible to pre-set these properties for the HTML file input element (or any upload control)? So when the user clicks 'browse' to select the file to upload, then the dialog has preselected the filename.
Btw, assume that this is for an intranet where the necessary directory/file do exist locally.
Unless it is a custom upload control, this cannot be done for security reasons.
If a html page could set the file to be uploaded using javascript, for instance, an arbitrary html page could upload any file from the client computer (form submission can be triggered via javascript)
This type of interaction with file-upload controls is disabled for security reasons.