我正在为工作编写一个自定义应用程序。该应用程序将为我们的客户项目创建一个文件夹结构。我正在创建程序的机器在从代码窗口调试和构建调试编译二进制文件后都可以工作。创建文件夹没有问题。另一台测试机,一台旧的win7机器,工作正常,没有问题。
我将二进制应用程序文件交给我的同事为我测试,它在尝试创建下一部分文件夹时会引发错误。(最后错误(
他安装了 .Net 4.8(它在 4.7.2 上运行(。我已经检查并打开了注册表中的 LongFolderPath 标志,但它在我的主电脑上没有活动(也不是在 win7 机器中(。我在他的机器上安装了VS,以便我们可以逐步完成代码,并在下面的代码(注明(上发现它的错误。
以下是添加文件夹结构的完整代码: https://pastebin.com/E26UFeuz
以下是在该台计算机上失败的相关部分的剪辑。
siteTypeName = "NSB";
projectPath = "C:\Test\";
private void createDirectoryStructure(string siteNumber, string siteName, string siteProject)
{
...
string[] siteProjectFolderTemplate = {
"100 - Existing Data",
"200 - Site Walk Info",
"300 - Drawings",
"400 - Engineering",
"500 - Photo Sims",
"600 - Surveys",
"700 - RFDS",
"1000 - File Reveiw",
"2000 - Leasing",
"3000 - Zoning",
"4000 - Permitting",
"5000 - Subcontractor Services",
"6000 - NTP",
"7000 - SAQ File Closeout Docs",
"8000 - Submittal Documents and QCs",
"9000 - SCIP"
};
...
//This is the section that breaks.
for (int j = 0; j < siteProjectFolderTemplate.Length; j++)
{
System.IO.Directory.CreateDirectory(projectPath +
cboClient.Text + "\" +
cboMarket.Text + "\" +
siteTypeName + "\" +
siteNumber + "_" + siteName + "\" + siteProject +
"\" + siteProjectFolderTemplate[j]
);
}
...
}
错误消息如下:
************** Exception Text **************
System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:TestClientMarketNSBKSMO-P-041370_AL2500 GSM 100 - Existing Data'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj, Boolean checkHost)
at System.IO.Directory.InternalCreateDirectoryHelper(String path, Boolean checkHost)
at System.IO.Directory.CreateDirectory(String path)
at AE_CreateFolderStructures.frm_CreateDirectoryStructure.createDirectoryStructure(String siteNumber, String siteName, String siteProject) in C:Code ProjectsAE-CreateFolderStructuresAE-CreateFolderStructuresfrm_CreateDirectoryStructure.cs:line 547
at AE_CreateFolderStructures.frm_CreateDirectoryStructure.btnImportCSV_Click(Object sender, EventArgs e) in C:Code ProjectsAE-CreateFolderStructuresAE-CreateFolderStructuresfrm_CreateDirectoryStructure.cs:line 917
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
所以回顾一下..的3台机器,在1台机器上崩溃并出现上述错误,似乎无法在某个点之后制作文件夹。
有什么想法吗?
路径是边走边创建的......它是'\L2500 GSM \'部分末尾的空间。我用.Trim(( 添加到路径构建的每个组件中。
功劳归于帕诺斯卡拉约翰