Reputation: 458
I have a file path in my default.aspx.cs page like this: http://localhost/data/Download/Import/Test.xlsx
I want to read this file using EFPlus library and make some changes. But I am not able to read its content and getting error like "URI Format not supported". If I read file directly from physical path then everything works fine. Below is my code snippet.
Dim newFile As New FileInfo
Upvotes: 1
Views: 1154
Reputation: 458
I found the solution, its not possible to get physical path of a file and read it using any library if we have URL like http://localhost/data/Download/Import/Test.xlsx. We have to give physical path of server if file is not in same directory where website code exists, only then we can read and access that file.
Upvotes: 0
Reputation: 4658
You need to use function Server.MapPath
, described here. This function generates a path relative to the root folder of your site. The input starts with a tilde ~
, which means the root. I.e.
Server.MapPath("~/images")
will return a string pointing to your /images folder.
Upvotes: 1