How do I allow the user to select the path for a file? - asp.net

In an application I'm working on, the users are prompted for the path of a file. This path will always point to a network drive, which the server has access to.
Currently, we use an asp:FileUpload control to accomplish this, drawing the path from the FileUpload's PostedFile.FileName property.
The problem is that the files the user is selecting from are locked down pretty severely. While the server has full access to them, the user only has permission to view the directory contents... They can't even open the files. This has worked fine up until now... But Windows 7 won't display these files in the file picker generated by FileUpload, so we need an alternative.
Notes:
Looking for a way to get UI similar to the file open dialog already in place.
The ability to view the client's local files (including the shared network drives) is a bonus, although listing the files through the server is acceptable.

I think the problem is the permissions on these files. If the users can't even open them, how can their terminal possibly upload them to a website?
I'm surprised this has ever worked.
If the user is simply supplying a path and not actually uploading the file you could have the server display the contents of the folder (in a list or whatever) and the user selects from that.

So how about creating a file browser in a window, such that a user clicks "Pick File" which opens a new window showing the root contents of the network drive. The user can then navigate round the directories to the file they want, finally clicking the file to "upload".
Use System.IO Directory.GetFiles to get the files in a directory.

I think you need to separate out the two things. Here's an example prompt to convey the idea:
Select a (file from your computer) OR (file from the server)
Client Files
You can use the standard file-upload control, that is fine.
Server Files
No user should be selecting files from your sever with the upload-file dialog. (Keep in mind that these dialog boxes allow right-click menus delete, copy, properties, etc and locked down or not, the user should not think they have this ability).
I don't think there are any controls that will "do-it-all" for you in this manner. I think your best bet is to make your own interface here.

Related

Telerik rad async file upload control is working well locally but not in server

I am using RadAsyncUpload control from Telerik to upload a file on the server. It is working well locally (on localhost) but not in the server. What did I miss?
(When I select a file to upload the dot becomes red instead of green)
I had the same behavior and it was a folder permissions issue.
Another symptom in this case, Chrome DevTools console was showing the following error when I attempt to upload a file:
HTTP Error code is 500
There is a temp folder where RadAsyncUpload saves files temporarily. If you don't define the TemporaryFolder property on the RadAsyncUpload control, the default will be in your App_Data\RadUploadTemp folder. If IIS_USERS don't have write permissions to this folder, the upload can't save a file here. It will work on your localhost because you have write permissions to that folder. Here's how to give the permissions necessary.
Right click on the App_Data\RadUploadTemp folder on server and
select proprties
Select Security tab
Click "Edit..." button
Under "Group or user names:", select IIS_USERS
Under "Permissions for IIS_USERS", check Write in the Allow
column.
Note: This was IIS 7 on Windows 2008 R2 Server.
The dot could become red either when the allowed file extension validation failed or when the file size exceeds the allowed one.
You can attach to the OnClientValidationFailed and OnClientFileUploadFailed events and check what the exact error is and fix it.
The Troubleshooting article offers additional information about the different errors and how to solve them.

Browse for file window without uploading the file

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.

asp:FileUpload fetch the file Path

VS 2008
How to fetch the Full File path for the File Uploaded in asp.net ??
Either HTML or ASP.Net Server Control, i need to use File Upload - Browse feature and need to fetch the Complete file path.
My guess is Due to security reasons, ASP.Net does not support asp:FileUpload to deliver the Full File Path ..!
What would be the best way to get the file path ?
You can't do what you want by design (at least on modern browsers). This would be a security issue if you could.
You can read more about this here.
Snipit:
Historically, the HTML File Upload
Control () has been
the source of a significant number of
information disclosure
vulnerabilities. To resolve these
issues, two changes were made to the
behavior of the control.
To block attacks that rely on
“stealing” keystrokes to
surreptitiously trick the user into
typing a local file path into the
control, the File Path edit box is now
read-only. The user must explicitly
select a file for upload using the
File Browse dialog.
IE8 read-only File Path box
Additionally, the “Include local
directory path when uploading files”
URLAction has been set to "Disable"
for the Internet Zone. This change
prevents leakage of potentially
sensitive local file-system
information to the Internet. For
instance, rather than submitting the
full path
C:\users\ericlaw\documents\secret\image.png,
Internet Explorer 8 will now submit
only the filename image.png.

Can you receive UNC path from a browser file dialog prompt?

We have a file upload in our ASP.NET MVC application that works fine. It engages the browser file dialog box and performs an upload on the selected file. Now, we're interested to receive the UNC path from the file (for different mapped drives) if possible. Can this be done?
What we'd like to do is if it's a non local resource, we'd like to pass up the UNC path rather upload since our server could access it much quicker.
The file input control will be able to use whatever the client computer can, be it UNC or local. The file will be uploaded via the client.
If you want to extract this path from the upload, this is not possible due to security considerations.
You may need to ask the user to input the file path to a text field in order to determine if it is local or on a network share, then decide what method to use in order to obtain the file.

Open File Dialog Asp.Net

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

Resources