Last active
December 11, 2020 17:55
-
-
Save devfred/3980418 to your computer and use it in GitHub Desktop.
csharp: Function that acts like PHP's file_get_contents
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected string file_get_contents(string fileName) | |
{ | |
string sContents = string.Empty; | |
if (fileName.ToLower().IndexOf("http:") > -1){ | |
// URL | |
System.Net.WebClient wc = new System.Net.WebClient(); | |
byte[] response = wc.DownloadData(fileName); | |
sContents = System.Text.Encoding.ASCII.GetString(response); | |
} else { | |
// Regular Filename | |
System.IO.StreamReader sr = new System.IO.StreamReader(fileName); | |
sContents = sr.ReadToEnd(); | |
sr.Close(); | |
} | |
return sContents; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment