Saturday, November 14, 2009

Linking to files without read-only restrictions

Here's another interesting programming trick I discovered at work recently that I was unable to find a solution to anywhere on the Internet:

Everyone knows that what makes the Internet the Internet is that everything is interconnected through links. Typically, these links connect to webpages with Internet-friendly file extensions, like ".htm" or ".html". One of these links would look like this: But it is also possible to link to files that are not typically found on the Internet, like Microsoft Word (.doc) and Microsoft Excel (.xls) documents. This is done in the same way: The difference is that this link will bring up a dialog box asking if the user wants to Open or Save the document. Choosing to open the document will open a read-only version of the document. Choosing to save the document will open a Save As dialog, with the usual options for filename and location.

But what if the document in question is a collaborative one that the programmer wishes users to be able to update directly? How does he get around the read-only restriction of a standard link? The answer is to use a Universal Naming Convention (UNC) path instead of a Uniform Resource Locator (URL) path in the link. In HTML, a link of this type would look something like this:

Link to file using UNC path instead of URL path
Note the backslashes and the use of the entire path to the file, starting with the server name or IP address. The only other trick to making this link work is that the "docs" directory must be set up with public "write" rights, so the programmer would want to be careful about what files were shared in this way.

If you share my line of work, give this a try and see for yourself how well it works. Good luck!

No comments: