这里我尝试生成Excel文件,该文件保存到我的本地应用程序文件夹,但即时得到错误“URI格式不被支持。”,任何一个可以告诉我为什么mgetting这正在收到错误“不支持URI格式。”
File.WriteAllText(ClsCommon.ApplicationPath + "TR_Temp/" + "AssessmentSheet.xls", renderedGridView);
这里我尝试生成Excel文件,该文件保存到我的本地应用程序文件夹,但即时得到错误“URI格式不被支持。”,任何一个可以告诉我为什么mgetting这正在收到错误“不支持URI格式。”
File.WriteAllText(ClsCommon.ApplicationPath + "TR_Temp/" + "AssessmentSheet.xls", renderedGridView);
在评论你提及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()
来避免这些类型的错误是个好主意。
使用方法
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()
那么什么是'ClsCommon.ApplicationPath'? –
始终使用System.IO.Path.Combine()创建路径和文件名。 – Heslacher
ClsCommon.ApplicationPath给我的本地applcation path.its一个comman类,我写应用程序路径的属性 – SANDEEP