views:

2586

answers:

5

hi, I was wondering if there was any method to implement browser's download file prompt using javascript. My reason - well users will be uploading files to a local fileserver which cannot be accessed from the webserver. In other words, both will be on different domains! e.g. let’s say websites hosted on www.xyz.com, but files would reside on local file server with address like \10.10.10.01\Files\file.txt. How am I uploading/transferring file to local fileserver... using ACTIVEX(yikes) & VBscript!!!! (don’t ask :-)

so i am storing local file path in my database and binding that data to a grid. So when the user clicks on that link, the file opens in a window (using javascript).

Problem is certain file types like text, jpg, pdf, etc open inside browser window. How would i be able to implement content-type or content-disposition using client side scripting? Is that even possible?

hoping my description was clear. Any ideas?

EDIT: the local file server has a window's shared folder on which the files are saved.

+1  A: 

I am pretty sure there is no way to do it with javascript.

Koistya Navin
aix
+2  A: 

"content-disposition: attachment" is pretty much the only way to force that, and this MUST be set in the response header.

John Gietzen
How can i set it on the client side? Currently i am using javascript to open the file. Calling window.open('\\10.10.10.01\Files\file.txt') to open the file. This would open the file in a window. Isnt "content-disposition: attachment" a server side response header setting?
aix
As the question said "this must be set in the response header", you can't set it on the client.
David Dorward
+1  A: 

Take a look at this article on content-disposition. As said, it has to be set in the response header, and isn't a Javascript implementation.

Perspx
Copying comments from above-How can i set it on the client side? currently i am using javascript to open the file. Calling window.open('\\10.10.10.01\Files\file.txt') to open the file. This would open the file in a window. Isnt "content-disposition: attachment" a server side response header setting?
aix
Yes, it is a server-side heading. Take a look at this article: http://www.jtricks.com/bits/content_disposition.html However, as it notes, the JS implementation is patchy, and my have become obsolete in versions > IE 6
Perspx
A: 

You could try using a plain hyperlink with type="application/octet-stream". Seems to work in FF, but IE and Opera ignore the attribute.

Christoph
By spec, IE and Opera are right. The type attribute says "Expect this from the server" so that clients which don't understand a particular content type can avoid bothering to try to download it (most useful with bots). The real Content-Type trumps it.
David Dorward
In my opinion, IE and Opera are wrong: in absence of any other content-type information (which is the case here), the 'advisory hint' (HTML spec) given by the type atttribute should be respected by the browser; remeber, the file isn't sent via HTTP, so there's no Content-Type field which could trump the attribute
Christoph
A: 

Hello Aix, I am trying to do what you did, my asp.net application have .doc and .pdf files that need to be openen in the browser when the user select their links. I was putting these files in a folder under the application's folder in wwwroot directory and opening the files using the following javascript:

window.self.open('http://servername/applicationname/Uploads/doc/' + filename + '.doc');

Now due to increase number of documents which takes much space, it was required to move the files to a shared folder in another server. I tried to open these files using script

window.self.open('\\servername\AppFiles\Uploads\doc\'+ filename + '.doc');

But I got The page cannot be found error because the output in the url was changed to http://servername/servernameAppFilesUploadsDocABC.doc!

Please advice how can I open files from a shared folder in another server from the asp.net application using javascript?

cloud
If you have a question. Ask a question. This is not an answer.
David Dorward