I am trying to develop a web page which will allow users to download to the Directory of there Choice. In my search to find away to do this, I had found that you can't use "FolderBrowserDialog". I am also finding that the examples online will only search the websrver directeory path and not the local machine. Is there anyway to get the Directory Path? I have the code to FTP the File Down, I just have to replace the code for "FolderBrowserDialog".
This isn't really up to you as a website, it's really the browsers job to store where they want files downloaded to. There is a pretty necessary separation between the website and client machine going on here.
In a web application you can't arbitrarily read or write stuff on the user's computer. That would be a gaping security hole, so it just can't be done. The 'Save As' dialog is something that happens entirely client-side. Your control over the download process ends as soon as you set the MIME type and send the file data away.
Browsers wont usually let you to choose location for individual download. you can change your browser settings to update the download folder. If you want to have this in your webpage, you probably need to have an activex control. this activex control can show the directories in the client machine so that user can select those. You need to write code to download the file to that location using the WebClient.DownloadFile method.
http://msdn.microsoft.com/en-us/library/ez801hhe.aspx
Don't expect this activex control works with all your users.Browsers usually block activex control or prompt the user (if the setting is like that).
Related
I have a server where word files are stored, i want by pressing a link the user can open the word file from the server, edit in it then saving it back to the server.
till now i figured out that i cant do so directly, but to save the file locally , edit on it then upload it back again.
so is there is a better way to do so? if not how to wait till the file is saved then automatically be uploaded again .
I think your best bet is probably to look into some of the controls out there you can buy to do this. Not necessarily cheap but depends on how much you need this functionality:
https://www.syncfusion.com/aspnet-mvc-ui-controls/word-processor
Regarding detecting a file change locally... you can use the FileSystemWatcher to do this on a folder... this isn't something that will work inherently from a website though. YOu would need to implement and distribute a windows service that your users would install and they would need to download the file they were changing into the folder(s) that your FileSystemWatcher was watching...
https://learn.microsoft.com/en-us/dotnet/api/system.io.filesystemwatcher?view=netframework-4.8
https://learn.microsoft.com/en-us/dotnet/framework/windows-services/walkthrough-creating-a-windows-service-application-in-the-component-designer
Hope this helps.
I'm trying to retrieve a file from the Process.Start()-Method.
Following scenario is given:
I obtain a link from a third party program. This link can be a UNC-path, direct link to PDF/JPG/TIF-files, such as "www.certainServer.de/test.pdf", as well as link to programs on the server, which return a special file type, such as "www.certainServer.de/test.aspx".
I open the file like this
Process.Start(_path)
If the link is like "www.certainServer.de/test.aspx" the returned file is automatically downloaded to the deposited download folder.
Is there a opportunity to retrieve the downloaded file or the path to the downloaded file?
The returned Process-object from the Process.Start()-Method doesn't seem to be helpful.
Process.Start does not necessarily download a file. It simply starts a process. You just as easily could start Notepad, which has no side effects (except, of course, what you do with notepad once it's started). If the process you start (in your case, calling a web page) has external effects, the process engine knows nothing about it.
It sounds like you know where the file is supposed to be deposited, so you could use something like a FileSystemWatcher to be alerted when a new file is added (which doesn't necessarily mean it came from your process, though) or get a list of files before and after the process is run.
But there's nothing inherent to System.Process to definitively know what that process did.
Another option might be to call the URL from your code (using WebClient or something similar) and capturing the result (which might be a file, or just a web page, depending on the URL). It's not as general as starting a process and letting the default browser handle the download, but it would capture the results more definitively.
I have an asp.net page that allows a user to select an excel file on his computer and then (1) upload it to the server, and (2) import into a SQL server table. This works fine.
Now I want to enhance the pages functionality to allow the user to select a directory on his computer and then automatically upload/import EACH file (Only of types xls, xlsx) in the clients directory. How can I do this? (Alternatively the user can select a file and then check a checkbox that says "upload all files in this directory", then it will process each file, etc.)
I found a way to loop thru the directory on the server side. But I can't figure it out for client side. Thanks!
You can't. Or at least, you shouldn't be able to.
A properly written browser specifically prevents direct access to the file system of the computer it is running on as a security precaution. The only "correct" way to access a file on a remote machine is to use the browser's File Upload form control on the page and have the user specify the file (or files) they want to send you.
Basically, no.
Many advances have been made in browser security to stop people doing this sort of thing.
The main solution is to use some kind of local plugin that gives this sort of access, but as this can be used for many nefarious deeds, it's very much frowned upon now.
You can of course let the user choose many files, there are various methods for doing this - but you can't automate it by the browser.
What's to stop someone searching for 'creditscards.txt' and uploading it without the user being aware?
One way I can think of is a Java applet. This is executed locally and has full access to the computer and the browser. They are being shut down for similar reason: it's just not safe.
I have outlined a way, but I must emphasize that this must be avoided. It's not because you can that you should.
I want to download Word file with FTP (thanks to webClient object). It's working fine but not in this case :
Users of my company can open this Word files. So, when a user has opened a file the DownloadData command returns an exception :
error 550 : File unavailable (e.g., file not found, no access).
There is a way to download an opened file with FTP ? If not, what can i do ?
Thanks !
This is almost assuredly a poor architecture for whatever project you are working on. You probably want to separate the user editable document store from the downloadable document store. There are many solutions for keeping the two directories in sync when a change is made by a user (dropbox, mesh, or even custom scripts using robocopy and such).
When an Office program opens a file for modification, it intentionally opens it exclusively. As a result, no FTP server is going to be able to open it, unless it uses the backup API. If it uses the backup API, it may well get some intermediate state, since Office may be in the middle of writing something at any time. So no sane person implements an FTP server to use the backup API.
I have task to give in my application possibility to open document that is located on server, but I dont know at all how to implement this.
Please give the main idea how can i do this?
If you are trying to open a file based on it's MIME extension and not prompt the user, you really can't do that in a Silverlight web application (for either case, MIME launching or opening a file without prompting the user). Silverlight isn't a "browser standard", and a lot of it's seemingly crippled features are done so out of the name of security, and a safer user experience. (You don't want a Silverlight app randomly reading files on your hard drive without you knowing about it and silently uploading them somewhere now, do you?)
I believe you can do whatever it is you're trying to do in Silverlight 4, but it requires elevated permissions (and consequently that it must be installed out of browser), and a little bit of COM hackery.
The elevated permissions do not give you direct access to files outside of the "My" Folders, so I don't think you are going to be able to do what you want if you want to preserve cross platform compatibility to the Mac.
However, if you don't care about that, you can do just about anything you want regarding file access by utilizing the Windows system COM objects (specifically the WScript.Shell and Scripting.FileSystemObject objects).
Here's and example.
Scroll to the section of COM Interoperability.