[英]getting Error “URI formats are not supported.”
在這里,我試圖生成excel文件並將此文件保存到我的本地應用程序文件夾中,但是我收到錯誤消息“不支持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);
將renderGridView的內容寫入文件。 請參閱: System.IO.Path.Combine()和System.IO.Path.GetTempPath()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.