简体   繁体   English

C#ClickOnce部署映射回到我的桌面驱动器

[英]C# ClickOnce Deployment Mapping Back to My Desktop Drive

I created a WinForms application that includes code to find the user's desktop and perform 3 tasks: 1. Create a folder 2. Read a .csv file 3. Output some data to a .csv file on the desktop. 我创建了一个WinForms应用程序,该应用程序包含用于查找用户桌面并执行3个任务的代码:1.创建文件夹2.读取.csv文件3.将一些数据输出到桌面上的.csv文件。

I'm using the code below to find the user's desktop 我正在使用下面的代码查找用户的桌面

    string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

I used the ClickOnce deployment to install the program to our network drive. 我使用ClickOnce部署将程序安装到我们的网络驱动器。 The program installs successfully, but Whenever I have someone attempt to run the program from their terminal, they get an error message that states "The directory name is invalid" and it references my desktop and not the user's. 该程序安装成功,但是每当有人尝试从其终端运行该程序时,他们都会收到一条错误消息,指出“目录名称无效”,它引用了我的桌面而不是用户的桌面。

How should I change my code or the deployment method so it references the user's desktop? 我应该如何更改代码或部署方法,使其引用用户的桌面?

If directory invalid try creating it Try with this code 如果目录无效,请尝试创建它。

 string filePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); 
 string extension = ".log"; filePath += @"\Error Log\" + extension;
  if (!Directory.Exists(filePath)) { 
 Directory.CreateDirectory(filePath); 
 }

我对代码进行了以下更改,并根据需要进行了更改:

string desktop = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM