簡體   English   中英

出現錯誤“不支持URI格式。”

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM