Skip to content

Instantly share code, notes, and snippets.

@devfred
Last active December 11, 2020 17:55
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devfred/3980418 to your computer and use it in GitHub Desktop.
Save devfred/3980418 to your computer and use it in GitHub Desktop.
csharp: Function that acts like PHP's file_get_contents
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