C# 通过ActiveX控件在JavaScript中启动应用程序时转义路径 客观的
我想通过JavaScript向.NET COM组件发送一个文件路径,而不必在JavaScript中转义它 环境 Windows 7 x64 .NET4.0 我们知道什么? 当您通过像C:\temp这样的路径时,您会得到以下结果。。。 当您传递诸如\\Server\目录之类的UNC路径时,您会得到以下结果。。。 当您转义路径(例如C:\\temp或\\\\Server\\Directory)时,收到的值是正确的。 我试过什么? 在存储到私有字段时,我尝试在变量名前面使用@。 我试着找人用我的谷歌浏览器做同样的事情,但是没有。 密码 COM组件 JavaScriptC# 通过ActiveX控件在JavaScript中启动应用程序时转义路径 客观的,c#,javascript,.net,activex,C#,Javascript,.net,Activex,我想通过JavaScript向.NET COM组件发送一个文件路径,而不必在JavaScript中转义它 环境 Windows 7 x64 .NET4.0 我们知道什么? 当您通过像C:\temp这样的路径时,您会得到以下结果。。。 当您传递诸如\\Server\目录之类的UNC路径时,您会得到以下结果。。。 当您转义路径(例如C:\\temp或\\\\Server\\Directory)时,收到的值是正确的。 我试过什么? 在存储到私有字段时,我尝试在变量名前面使用@。 我试着找人用我的谷歌浏
最后,我们发现我们只需要更改JavaScript,因为以后无法完成。当它到达我们的时候,我们将不得不添加反斜杠,但我们不能真正做到,因为我们不知道一个目录从哪里开始,另一个目录从哪里结束 只需修改JavaScript即可 因此,我们与强大的力量合作,一切都很好
[Guid("30307EE0-82D9-4917-B07C-D3AB185FEF13")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[ComVisible(true)]
public interface ILauncher
{
[DispId(1)]
void setDirectory(string location);
[DispId(2)]
void launch(string args, bool debug = false);
}
[Guid("F91A7E9F-2397-4DEC-BDAD-EBFC65CFCCB2")]
[ProgId("MyActiveXControl.MyControl")]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(ILauncher))]
[ComVisible(true)]
public class Launcher : ILauncher
{
private string _location;
public void setDirectory(string location)
{
_location = location;
}
public void launch(string args, bool debug = false)
{
var programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
if (string.IsNullOrEmpty(programFiles))
{
programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
}
var exe = string.Format(@"{0}\MyApp\MyApp.exe", programFiles);
if (debug)
{
MessageBox.Show(exe, "Target Path", MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBox.Show(_location, "Drop Location", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
var startInfo = new ProcessStartInfo(exe, string.Format("\"{0}\" \"{1}\"", args, _location));
startInfo.WorkingDirectory = Path.GetDirectoryName(exe);
startInfo.CreateNoWindow = false;
try
{
var p = Process.Start(startInfo);
if (p == null)
{
MessageBox.Show("The app could not be started, please try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
<html>
<body>
<input type="button" value="Launch Control" onclick="launchControl();" />
<script>
function launchControl() {
o = new ActiveXObject("MyActiveXControl.MyControl");
o.setDirectory("C:\\temp");
o.launch("test_args", true);
}
</script>
</body>
</html>