简体   繁体   English

出现错误“不支持URI格式。”

[英]getting Error “URI formats are not supported.”

在这里,我试图生成excel文件并将此文件保存到我的本地应用程序文件夹中,但是我收到错误消息“不支持URI格式。”,任何人都可以告诉我为什么要这样做

File.WriteAllText(ClsCommon.ApplicationPath + "TR_Temp/" + "AssessmentSheet.xls", renderedGridView);

In the comments you mention that ClsCommon.ApplicationPath is "localhost:1682/TR-WEB-Corp" . 在评论中,您提到了ClsCommon.ApplicationPath"localhost:1682/TR-WEB-Corp" That is, you are trying to write to a file with the path "localhost:1682/TR-WEB-CorpTR_Temp/AssessmentSheet.xls" . 也就是说,您正在尝试写入路径为"localhost:1682/TR-WEB-CorpTR_Temp/AssessmentSheet.xls"

This is not a path, but an URI. 这不是路径,而是URI。 A path is something on a local or a network disk and should either start with a drive name ( C: , D: , etc) or a network share name ( \\\\network\\share ). 路径是本地磁盘或网络磁盘上的某个路径,应以驱动器名称( C:D:等)或网络共享名称( \\\\network\\share )开头。

Also, your path seems to be missing a path separator (backslash) between ClsCommon.ApplicationPath and "TR_Temp/" . 另外,您的路径似乎缺少ClsCommon.ApplicationPath"TR_Temp/"之间的路径分隔符(反斜杠)。 As mentioned by @Heslacher in the comments, it's a good idea to use System.IO.Path.Combine() to avoid these kind of bugs. 正如@Heslacher在评论中提到的那样,最好使用System.IO.Path.Combine()来避免此类错误。

Using the methods 使用方法

System.IO.Path.GetTempPath()
System.IO.Path.Combine()

you can get a valid filename like: 您可以获得有效的文件名,例如:

string fileName = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "TR_Temp","AssessmentSheet.xls");
File.WriteAllText(fileName, renderedGridView);

to write the content of renderedGridView to a file. 将renderGridView的内容写入文件。 See: System.IO.Path.Combine() and System.IO.Path.GetTempPath() 请参阅: System.IO.Path.Combine()System.IO.Path.GetTempPath()

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

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