SANDEEP
SANDEEP

Reputation: 1082

getting Error "URI formats are not supported."

here i m trying to generate excel file and save this file to my local application folder but i m getting Error "URI formats are not supported.", can any one tell why i mgetting this

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

Upvotes: 0

Views: 1317

Answers (2)

Heslacher
Heslacher

Reputation: 2167

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. See: System.IO.Path.Combine() and System.IO.Path.GetTempPath()

Upvotes: 0

Torbjörn Kalin
Torbjörn Kalin

Reputation: 1986

In the comments you mention that ClsCommon.ApplicationPath is "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".

This is not a path, but an 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).

Also, your path seems to be missing a path separator (backslash) between ClsCommon.ApplicationPath and "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.

Upvotes: 1

Related Questions