获取错误“不支持URI格式”。

时间:2013-08-12 10:28:55

标签: c# file

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

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

2 个答案:

答案 0 :(得分:1)

在评论中,您提到ClsCommon.ApplicationPath"localhost:1682/TR-WEB-Corp"。也就是说,您尝试使用路径"localhost:1682/TR-WEB-CorpTR_Temp/AssessmentSheet.xls"写入文件。

这不是路径,而是URI。路径是本地或网络磁盘上的某个路径,应该以驱动器名称(C:D:等)或网络共享名称(\\network\share)开头。

此外,您的路径似乎缺少ClsCommon.ApplicationPath"TR_Temp/"之间的路径分隔符(反斜杠)。正如@Heslacher在评论中所提到的,使用System.IO.Path.Combine()来避免这些错误是个好主意。

答案 1 :(得分:0)

使用方法

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

您可以获得有效的文件名,如:

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

将renderedGridView的内容写入文件。 请参阅:System.IO.Path.Combine()System.IO.Path.GetTempPath()

相关问题