文件名有两个反斜杠 C#

File name has two backslashes C#(文件名有两个反斜杠 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#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)