0

.Net provides a useful FileWebRequest class to let you perform web-requests on a local file, and the very handy WebRequest.Create(uriString) method which returns the right type of object depending on the URI type (file, http, etc).

However what if I want to run a test which uses a file with a relative local path? I'm fairly sure a file URI mustn't be relative (from my tests and other SO answers) so what is the right approach here?

I see .NET can do the opposite through URI.LocalPath: https://msdn.microsoft.com/en-us/library/system.uri.localpath(v=vs.110).aspx

Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
  • You could use Server.MapPath to get the local folder, for the top of the app, and work out the differences? not very elegant mind – BugFinder Jun 08 '16 at 15:00
  • Why? What are you trying to do? And in what kind of environment? What does "local" mean? If relative path is the important part, why don't you just create an equivalent absolute path? – Luaan Jun 08 '16 at 15:05
  • @Luaan if that's the best/only way, please provide an answer - that's kind of the question I'm asking – Mr. Boy Jun 08 '16 at 15:08
  • I don't think this is a duplicate but _if_ we have to separately convert to absolute first, it provides the rest: http://stackoverflow.com/questions/1546419/convert-file-path-to-a-file-uri – Mr. Boy Jun 08 '16 at 15:11

0 Answers0