在c#中定位文件目录以显示pdf
我在单击菜单项时在表单中显示 pdf 时遇到问题 找不到我使用的目录 该文件位于项目文件夹中,
private void helpToolStripMenuItem_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(@"\\ColsTechieApp\\TechnicianApplicationUserManual.pdf");
}
当我输入完整位置时,
private void helpToolStripMenuItem_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(@"C:\Users\UV Chetty\Dropbox\Final\Complete\ColsTechieApp (Complete)\ColsTechieApp\Technician Application User Manual.pdf");
}
它的工作原理如何使路径独占到项目文件夹
I am having a problem with displaying a pdf in my form wen a menu item is clicked
the directory im using cant be found
the file is in the project folder
private void helpToolStripMenuItem_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(@"\\ColsTechieApp\\TechnicianApplicationUserManual.pdf");
}
when i enter the full location
private void helpToolStripMenuItem_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(@"C:\Users\UV Chetty\Dropbox\Final\Complete\ColsTechieApp (Complete)\ColsTechieApp\Technician Application User Manual.pdf");
}
it works how do i make the path exclusive to the project folder
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用
Environment.CurrentDirectory
作为当前设置并将其与Path.Combine
组合应该可以工作,因为您使用的是完整路径
Try using
Environment.CurrentDirectory
as your current set and combin it withPath.Combine
Should work, becaus you are using full path
首先,您尝试转义反斜杠,但 @ 指定不应转义字符串。 (另外,您似乎缺少空格)
其次,Environment.CurrentDirectory 插入当前路径。与 Path.Combine 一起使用,您将获得整个位置。
如果你真的很懒,你可以跳过 Path.Combine 并直接连接字符串。 Process.Start() 可能会自动将其转换为路径。
First, you're trying to escape backslashes but the @ specifies that the string shouldn't be escaped. (Plus, you seem to be missing whitespaces)
Secondly, Environment.CurrentDirectory inserts the current path. Used with Path.Combine, you'll have your entire location.
If you're really lazy, you can skip the Path.Combine and directly concatenate strings. Process.Start() probably converts it to a Path automatically.