我正在尝试将我的C#项目作为Click-once启动项目,但它没有读取文件夹目录,有人可以帮助我吗?这是我的代码。
private void SetStartUp()
{
string appName = "PMD Client";
string publisherName = "Novus May";
string startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
startupPath = Path.Combine(startupPath, appName) + ".appref-ms";
if (!File.Exists(startupPath))
{
string allProgramsPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
string shortcutPath = Path.Combine(allProgramsPath, publisherName);
shortcutPath = Path.Combine(shortcutPath, appName) + ".appref-ms";
File.Copy(shortcutPath, startupPath);
}
}
错误说System.IO.DirectoryNotFoundException:
你在做什么似乎有点奇怪。不确定你应该这样做。但是关于你的问题,我猜你已经错误地为shortcutPath添加了启动路径?
只需设置一个断点并逐步完成它?
File.Copy(shortcutPath, startupPath);
价值观:
shortcutPath:C:\Users\User\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\Novus May\PMD Client.appref-ms
(Startup文件夹似乎错误)。
startupPath:C:\Users\User\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\PMD Client.appref-ms
也许你想要这样的东西呢?我已经取出了“Startup”文件夹:
shortcutPath:
C:\Users\User\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Novus May\PMD Client.appref-ms