简体   繁体   中英

URL as FileName in OpenFileIDialog C#

In my C# win form I use an OpenFileDialog for users to select a file to save. When the user specified a url file like http://www.xyz.com/qdms/MyFile.PDF OpenFileDialog downloads the file and give the downloaded file from OpenFileDialog.FileName such as C:\\Documents and Settings\\MyName\\Local Settings\\Temporary Internet Files\\Content.IE5\\GPIR4TYV\\QDMS4[3].PDF and hangs a lot of time.

Is there any way to get http://www.xyz.com/qdms/MyFile.PDF as OpenFileDialog.FileName when user enter a url path?

and hangs a lot of time

A "hang" has a well defined meaning, it occurs when a program becomes unresponsive to user input, typically also suffering from painting artifacts and having its UI replaced by the ghost window, the one that says "Not responding" in the title bar.

None of this happens in the OpenFileDialog. It simply disables input but keeps the Cancel button operable while the download is progressing. A progress bar would have been nice but it is not a widget that's included in the dialog. Nothing hangs, the user can fire up Solitair and the dialog paints just fine when he switches back. If he gets tired of waiting then pressing the Cancel button works well.

No user is ever going to be flummoxed by this. You could use the FileOk event to have a look at the selected file before the download starts and display a warning that it might take a while. That however isn't terribly useful since you have no way to estimate how long it is going to take and is likely to just exhaust the user with an "I know, I know, stop telling me about the obvious" exclamation. Best to avoid helping here, you can if you want to.

I do not believe there is. When Windows recognises that the value entered is an internet protocol address, it will download it to a temp folder and use that filename to be shown/selected in the file dialog. The only other way would be to (and silly design) ask the user to enter a url first in a custom dialog, then take that value and store it. Finally, set the filename in the dialog and open it...see if it downloads it. when it does and the user hits "OK", take the path and replace the filename with the one the user entered previously in the dialog before you opened the open file dialog.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM