WebRequest is the type returned by the WebRequest.Create() factory method and is abstract .
According to the protocol recognized in the URL string, it returns a valid subclass, such as FileWebRequest or FtpWebRequest .
The problem in your code is that you are trying to create a request for a local file (file: //), so the factory returns FileWebRequest , but you make the code think that it has removed the HTTP URL. Just wrong .
This explains the fact that it only works with remote, not local, files.
source share