Accessing local file system on browser - javascript

Please hear me out before you start crying security issues.
This is for an intranet application, hence I have full range to install any plugins or change any security permissions to suit.
What I want is for them to go to a webpage and click a link to download a file, such as a Word Document. This gets transferred to local storage of some kind (sandboxed if need be) and then is opened in word as a regular file.
When they click save, JavaScript or something will pickup the file is saved or the program is no longer accessing it and can be actioned upon, such as uploading back up to the server.
Is there any way to do this. I have looked at IndexedDb, WebStorage, HTML5 FileSystem API but I am new to all and don't see a way to do this.
I am open to coding any needed plugins as long as you don't mention Flash. The main issue I am coming across is opening a file downloaded into some form of local browser and then opening it via a desktop application, e.g. Word.
Any help, greatly appreciated.

After much research the only way to do it is with a plugin. IndexedDB, FileSystem API or WebStorage can not access the local file system. Which is good.
Silverlight is a good option for intranet and .NET, which is what I have chosen to go with.
Silverlight 5 in full permissions with a file watcher. The file watcher can be accomplished with this method: Is there an alternative to accomplishing what the FileSystemWatcher does in Silverlight?

Related

Is it possible to using web api and open a local folder? [duplicate]

We are currently looking at porting a enterprise silverlight application over to html5. The major roadblock that we have hit is the ability to open files from the user's local disk. Currently they have a document library which just links to files on their computer that they can open from within the app and view or print out. All that I read is that you can only access the local sandbox of the web app with the html5 file api's. We want to load these files from code.
Does anyone know of any workarounds to this?
Thanks
There is no way for html5 to access local file without user selection. But FSO: FileSystemObject works for IE and MAYBE could be regarded as a work around. But still there are some requirements to meet.
It is possible to use chrome's filesystem API to access files on a users local filesytem. So you'd have to be willing to make this a chrome only application.
Using java you can create a "Signed" applet which has access to the local filesystem. (if the applet is signed you can request filesystm permissions)
then there is a tutorial for accessing methods of your java code directly from javascript here: http://docs.oracle.com/javase/tutorial/deployment/applet/invokingAppletMethodsFromJavaScript.html
you should be able to perform something similar from silverlight.
There is no workaround in pure HTML5/Javascript. You need the use of plugins, such as Java or Silverlight (maybe you shouldn't port it after all). As for workarounds, HTML5 gives you an easy way drag and drop multiple files that you could transfer on the server and then display back to your users. Another workaround would be to install a custom agent (a software with only a tray icon) that would send the information about the current user "document library" to server and then again, you could display it back to the user.
Note: I've heard somewhere that browsers will eventually stop supporting plugins. http://www.howtogeek.com/179213/why-browser-plug-ins-are-going-away-and-whats-replacing-them/
Ya, I agree with Markain. However, if you were to limit your audience solely to chrome users, I daresay, you would most likely use some of your users. If Huazhihao is right, then your number of leaving customers should decrease but users who regularly use firefox won't be happy. Overall, I think that this will not work. Otherwise, there would be too many websites that trashed your hard driver (or at least wherever you have the rights to edit/delete files). I think it would be best if your product was setup to synchronize the file whenever an internet connection was detected and a change was made to the file. That way the user would not need to visit the website whenever the file was uploaded. If this is some kind of an error file, then it would be most beneficial if you were to make a link in the application that when clicked, would upload the file to the website and the website were to do whatever was necessary. If this is a purely online thing, then I don't see what business you would have looking through other peoples' files =-). Hope I helped!

How to search the Local file system of Windows using Javascript?

Operating system : Windows 8.
Input-from : A text field from a html page .
Input-type: text.
Output : the file that was searched.
What I want : I want the user to enter some keywords and have JavaScript search the user's local files...
Is there any way? or A javascript Library?....
And how I can query the file system about the files using Javascript..in Windows..
EDIT::
Thanks everyone for the reply...
The way I get it is ,either I have to develop my own browser based in Java that has sufficient permissions.. or
I would have to implement a file crawler that indexes everything that sends that file to the a server , so that javascript can then access it through xmlhttp requests to the server ....
This was just a curiosity and I don't want to expose anyone's personal files on the Internet.
A fun project.. That all tinkered in my mind.
This is not possible from a web page because of the browser's security restrictions. You could access the local file system with Node.js or an Electron app, but I don't know if that would suit your use case
No. That's simply not possible and even if it is, it should not be used, as it would make one's local file system open to various threats because you are directly exposing your machine on the internet. That's sufficient enough reason for a webapp not to access one's local file system in any manner whatsoever.
P.S: If you really want it, There are a few third party libraries which use Sandboxed file systems. You can try that if you want.
I havent tried it personally, but found the below link via quick googling so i am not sure if its officially supported up until now.
https://www.html5rocks.com/en/tutorials/file/filesystem/
Use <input type="file">, which implements ability for user to select file from local filesystem.

Some questions about HTML5 FileSystemAPI

I'm a first time user, just in the initial stages figuring out if this is going to be useful for me, so forgive any naive questions. I'm using Google Chrome.
Here's my use case -
The user needs to store some information to my application(web based) which may include paths to some files on his system. When the user comes back to access this information via my application, he should be able to click on the links that point to these files on his local disk and open those files.
Now, we know that browsers will not allow this due to security concerns.
I had the following questions
The description for HTML5 FileSystemAPI says that this will allow us to access files from a "sandboxed" section of the users disk.
Does that mean that the files that my user wants to read should only originate from a specific folder on his disk?
Do we get to decide what that location would be? File browser access to Chrome's sandboxed filesystems - i get the idea from this question that chrome decides that.
I would appreciate if someone could throw some light on this. Thanks guys.
AFAIK, the FileSystem API doesn't provide access to files outside the sandbox and the sandbox's location is imposed by the browser. You can use HTML5's File API to let the user upload data, and then store this data using the FileSystem API. However, I don't think this is what you want.
Unrestricted access to a user's filesystem is only possible through a Java applet or another plugin.

html or javascript, how to find out where is the program files folder?

i have some HTML files that i want to run in user local machine ( offline).
is there any method to find out in which hard drive the program files folder is located?
Note: do you know any methods that don't raise security problems.
I think this question is very confused. Not every computer has a "Program Files" directory or even the concept of drives because not every computer is Windows.
On top of that, HTML5 Offline Mode just requires a manifest file to be hosted by your web server. The browser will put the cached data in the right place for it.
If you're talking about some internal deployment of a non-hosted page and want to spawn IE directly, I think it's a bad idea, but use the %ProgramFiles% environment variable.
There is a file system api in HTML5 - have a look at the draft documentation
If you're calling requestFileSystem() for the first time, new storage is created for your app. It's important to remember that this file system is sandboxed, meaning one web app cannot access another app's files. This also means you cannot read/write files to an arbitrary folder on the user's hard drive (for example My Pictures, My Documents, etc.).
So if you're thinking about a web page being able to poke around a users program folder, then the answer is no, you'll need some kind of an app engine - e.g. Adobe Air or the Windows8 Metro apps.
Basically there is no crossbrowser way of doing this. If it is ok for you to have an Internet Explorer only solution try to look at the ActiveX component called FileSystemObject and its GetSpecialFolder method - http://msdn.microsoft.com/en-us/library/aa265315%28v=vs.60%29.aspx
I'm not on Windows but it seems you can try something like this:
var WshShell = new ActiveXObject('WScript.Shell');
Response.write("ProgramFiles envioronment variable is set to:\n\n" +
WshShell.ExpandEnvironmentStrings('%ProgramFiles%'));
Program Files are found on Environment Variables, so that's what you're looking for.
Regards,
PS: this will lead you to some security warnings. Actually, this is not safe.

open a file with its default programme

In my application I want to open some files with the correct default programmes, like .doc file should be open with WORD and .psd files should be opened with Photoshop if it is installed, and this should be done under html or java script.
Please tell me how to do it.
JavaScript cannot run programs, but if you have a file on your server you can simply link to it:
<a href='image.psd'>Download File</a>
Users will be promped to download the file or open it using the default program (for most files). Again - as others have said - this is determined by the browser. IE can open doc files on the browsers, and PDF documents can be opened that way too.
There is no way for you to choose which application will be used to open your files with javascript...It just doesn't have that power.
I don't think this is possible in JavaScript without using any activeX or something like that. Js has no access to locally installed applications.
Browsers typically don't have access to the computer's filesystem for security reasons. If you know the exact path to a file you can point the browser at it using a file: URI, e.g.
file:///C:/path/to/file.ext
You may also be able to do this with a plugin, eg ActiveX, however I am unsure as to what security measures that would have.
Invoke the system command 'open'. Works on Windows and Unix based clients.
Depending on where your script runs, you might not be able to invoke system commands though, for instance in a browser sandbox.
If you provide a link to a file on the local file system (eg: <a href="file:///C:/mydoc.doc">) then the browser will open it - however this is not a great way to do it since the browser will first show a dialog ("Do you wish to Save or Open") and then it will "download" it into temporary files as it would if the file were remote. In this case, if you edit and save the file, it'll be the version now in your temp folder. This might not be a problem if your files are read-only, but generally it's not a great user experience.
The only other method is to use ActiveX, which is actually rather easy (though I don't have the exact code on me now - write a comment if you're interested in a snippet and I'll update). Of course this comes with the giant flashing caveats of:
It only works in Internet Explorer.
You need the user to fiddle with their security settings for the ActiveX scripts to run.

Categories

Resources