开发者

How open a local file with the associated program from a web page?

开发者 https://www.devze.com 2022-12-21 23:08 出处:网络
I know the user of my app has a local file named c:\\sourcefile.cs, I need to find a way to render a link to that file so that when he clicks the link, it will open the file in Visual Studio.

I know the user of my app has a local file named c:\sourcefile.cs, I need to find a way to render a link to that file so that when he clicks the link, it will open the file in Visual Studio.

This is for internal use in our dev team so I don't mind using unconventional means to do that if there is no standard way to do it.

The solution has to work w开发者_开发百科ith Firefox.


This is not possible because of security reasons. Javascript in the browser cannot access the clients computer.

You would need to use a Java applet or something else like that to make that happen.


You should ask users of your app (since it is for internal use) to change a firefox option

Tools -> Options -> Applications(tab)

There they should associate the .cs with the action you want (to open the VS)..

now using the <a href="file:///c:/sourcefile.cs"> should work..

[update]

Seems like firefox has removed the option to add a new mimetype..

there is a manual workaround..

You will need to locate the firefox profile (located at : APPDATA%\Mozilla\Firefox\Profiles\xxxxxxxx.default\ )

and then edit the file mimeTypes.rdf

add the following element

<RDF:Description RDF:about="urn:mimetype:text/cs"
                   NC:value="text/cs"
                   NC:editable="true"
                   NC:fileExtensions="cs"
                   NC:description="CSharp Source File">
    <NC:handlerProp RDF:resource="urn:mimetype:handler:text/cs"/>
</RDF:Description>

and also find the existing <RDF:Seq RDF:about="urn:mimetypes:root"> and add to it the

<RDF:li RDF:resource="urn:mimetype:text/cs"/>

Now you can edit it with from the applications tab as shown earlier..


You will have to use some sort of binary code (meaning, non-JavaScript) which will more than likely require explicit permission on the user's part to access the browser's hard drive.

For FireFox, the way to do this is through a Plugin which will give the browser the capability (or at least your plugin the capability through the browser) to do what you want, while getting the explicit security permissions.

You should start with the API for FireFox plugins and go from there. This is a FireFox-specific solution.

If you want something that is browser-agnostic at some point, you might want to look into embedding a Java applet into the page. Of course, this will require permissions from the user for the applet to access the hard drive, but it will work in any browser that has the Java plugin installed.


I don't know about opening in visual studio, but this might work:

file:///c:/sourcefile.cs

It depends on browser, browser settings, and of course file associations.


You can use a link;

<a href="file:///c:/sourcefile.cs">Open File</a>

That should open the file with the default application.


Latest firefox (3.6) maybe could help, try search "file api". Or you can use java applets.

0

精彩评论

暂无评论...
验证码 换一张
取 消