我目前正在开发一些实现一些复杂计算的功能。计算本身在 Word 文档中进行了解释和定义。
我想要做的是在每个引用关联 Word 文档的代码文件中创建一个超链接 - 就像在 Word 本身中一样。理想情况下,此链接应放置在每个类的 XML 注释中或附近。
这些文件驻留在网络共享上,无需担心权限。
到目前为止,我有以下内容,但总是出现文件未找到错误。
file:///\\165.195.209.3\engdisk1\My Tool\Calculations\111-07 MyToolCalcOne.docx
我已经解决了问题是由于文件夹和文件名中的空格造成的。
我的工具
111-07 MyToolCalcOne.docx
我尝试用 %20 替换空格,因此:
file:///\\165.195.209.3\engdisk1\My%20Tool\Calculations\111-07%20MyToolCalcOne.docx
但没有成功。
所以问题是;我可以用什么来代替空格?
或者,有更好的办法吗?
I am currently developing some functionality that implements some complex calculations. The calculations themselves are explained and defined in Word documents.
What I would like to do is create a hyperlink in each code file that references the assocciated Word document - just as you can in Word itself. Ideally this link would be placed in or near the XML comments for each class.
The files reside on a network share and there are no permissions to worry about.
So far I have the following but it always comes up with a file not found error.
file:///\\165.195.209.3\engdisk1\My Tool\Calculations\111-07 MyToolCalcOne.docx
I've worked out the problem is due to the spaces in the folder and filenames.
My Tool
111-07 MyToolCalcOne.docx
I tried replacing the spaces with %20, thus:
file:///\\165.195.209.3\engdisk1\My%20Tool\Calculations\111-07%20MyToolCalcOne.docx
but with no success.
So the question is; what can I use in place of the spaces?
Or, is there a better way?
发布评论
评论(1)
一种效果很好的方法是编写自己的 URL 处理程序。这绝对是微不足道的事情,但非常强大且有用。
可以设置注册表项,使操作系统在启动注册的 URL 时执行您选择的程序,并将 URL 文本作为命令行参数传入。只需几行简单的代码即可以您认为合适的任何方式解析 URL,以便找到并启动文档。
这样做的优点:
mydocs://MyToolCalcOne.docx
我建议不要在文件名和 URL 中使用空格 - 空格在 Windows 下从来没有正常工作过,并且迟早会导致问题(或需要像 %20 这样的丑陋)。最简单、最干净的解决方案就是删除空格或用下划线、破折号或句点等内容替换它们。
One way that works beautifully is to write your own URL handler. It's absolutely trivial to do, but so very powerful and useful.
A registry key can be set to make the OS execute a program of your choice when the registered URL is launched, with the URL text being passed in as a command-line argument. It just takes a few trivial lines of code to will parse the URL in any way you see fit in order to locate and launch the documentation.
The advantages of this:
mydocs://MyToolCalcOne.docx
I would advise against using spaces in filenames and URLs - spaces have never worked properly under Windows, and always cause problems (or require ugliness like %20) sooner or later. The easiest and cleanest solution is simply to remove the spaces or replace them with something like underscores, dashes or periods.