且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

错误:不支持给定路径的格式

更新时间:2022-12-28 17:57:56

我不知道您的计算机设置了什么文化,但我想调用DateTime.Now.ToString()会给您类似08/02/2017 11:41:30的内容,其中包含斜杠和冒号,并且因此不是有效路径.

I don't know what culture your machine is set to but I assume calling DateTime.Now.ToString() gives you something like 08/02/2017 11:41:30 which contains slashes and colons and is therefore not a valid path.

尝试在ToString()内部指定格式,如下所示:

Try specifying a format inside ToString() like this:

ss.SaveAsFile(projectPath+"Screenshots\\Drisha"+DateTime.Now.ToString("ddMMyyyyHHmmss")+".jpeg", ImageFormat.Jpeg); 

作为旁注,您不应串联字符串以构成路径,而应使用Path.Combine.

As a side note you should not be concatenating strings to make a path, instead use Path.Combine.

ss.SaveAsFile(Path.Combine(projectPath, "Screenshots\\Drisha", DateTime.Now.ToString("ddMMyyyyHHmmss"), ".jpeg"), ImageFormat.Jpeg);