We have a file (txt,doc,xml,xslt etc tested) and we wanted to read the content of that file into a string variable.
To do this I have following code section:
=-=-=-=-=-=-=-=-=-=-=-=-=-=
using System.IO;
public string GetContentsOfFile(string URL)
{
if(string.Equals(URL,string.Empty))
throw new ArgumentNullException("URL not given");
StreamReader sr = new StreamReader(URL);
string retStr = string.Empty;
retStr = sr.ReadToEnd();
return retStr;
}
=-=-=-=-=-=-=-=-=-=-=-=-=-=
This method will take URL of file as parameter and return a string with the contents of that file.
Enjoy...
To do this I have following code section:
=-=-=-=-=-=-=-=-=-=-=-=-=-=
using System.IO;
public string GetContentsOfFile(string URL)
{
if(string.Equals(URL,string.Empty))
throw new ArgumentNullException("URL not given");
StreamReader sr = new StreamReader(URL);
string retStr = string.Empty;
retStr = sr.ReadToEnd();
return retStr;
}
=-=-=-=-=-=-=-=-=-=-=-=-=-=
This method will take URL of file as parameter and return a string with the contents of that file.
Enjoy...
No comments:
Post a Comment