File name has two backslashes C#(文件名有两个反斜杠 C#)
问题描述
这可能有一个简单的答案,但是当我将 DateTime.Now.ToString() 添加到我的文件名时,它会为每个 添加一个额外的 我有所以 C:Temp 变为 C:\Temp 导致文件不保存.
There is probably an easy answer for this, but when I added DateTime.Now.ToString() to my fileName it adds an extra for every I have so C:Temp becomes C:\Temp which causes the file not to save.
这是有问题的代码
String fileName = @"C:Tempdata_" + DateTime.Now.ToString() + ".txt";
例如输出可能是 C:\Temp\data_12/04/2012 20:08:40.txt
应该是C:Tempdata_12/04/2012 20:08:40.txt
推荐答案
不,那个字符串真的里面有一个反斜杠.把它打印到控制台,你会看到的.
Nope, that string really has single backslashes in. Print it out to the console and you'll see that.
如果您在 调试器 中查看它,您会看到反斜杠已转义 - 但字符串本身具有单个反斜杠.这咬了很多人:(
If you look at it in the debugger, you'll see the backslashes escaped - but the string itself has single backslashes. This bites lots of people :(
这篇关于文件名有两个反斜杠 C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:文件名有两个反斜杠 C#
基础教程推荐
- C# 从 List<List<int>> 中删除重 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
