本文整理汇总了C#中System.IO.StreamReader类的典型用法代码示例。如果您正苦于以下问题:C# System.IO.StreamReader类的具体用法?C# System.IO.StreamReader怎么用?C# System.IO.StreamReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
System.IO.StreamReader类属于命名空间,在下文中一共展示了System.IO.StreamReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateFiles
public void UpdateFiles()
{
try
{
WriteLine("Local version: " + Start.m_Version);
WebClient wc = new WebClient();
string versionstr;
using(System.IO.StreamReader sr = new System.IO.StreamReader(wc.OpenRead(baseurl + "version.txt")))
{
versionstr = sr.ReadLine();
}
Version remoteversion = new Version(versionstr);
WriteLine("Remote version: " + remoteversion);
if(Start.m_Version < remoteversion)
{
foreach(string str in m_Files)
{
WriteLine("Updating: " + str);
wc.DownloadFile(baseurl + str, str);
}
}
wc.Dispose();
WriteLine("Update complete");
}
catch(Exception e)
{
WriteLine("Update failed:");
WriteLine(e);
}
this.Button_Ok.Enabled = true;
}
示例2: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
System.IO.StreamReader reader = new System.IO.StreamReader(HttpContext.Current.Request.InputStream);
string requestFromPost = reader.ReadToEnd();
//loop through
// string formValue;
string speed;
string initialLocation;
string finalLocation;
string IMEI;
if (!string.IsNullOrEmpty(Request.Form["txtSpeed"]))
{
//formValue = Request.Form["txtSpeed"];
//formValue = Request.Form["txtImei"];
speed = Request.Form["Speed"];
initialLocation = Request.Form["initialLocation"];
finalLocation = Request.Form["finalLocation"];
IMEI = Request.Form["IMEI"];
string s = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlConnection cn = new SqlConnection(s);
cn.Open();
SqlCommand cmd = new SqlCommand("insert into DataHistory(Speed, initialLocation, finalLocation, IMEI)values('" + speed + "','" + initialLocation + "','" + finalLocation + "','" + IMEI + "')", cn);
cmd.ExecuteNonQuery();
}
}
示例3: LoginNormal
private void LoginNormal(string username,string password,string data,ref CookieContainer cookies)
{
//POST login data
Dictionary<string,string> postData = new Dictionary<string, string> ();
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create ("https://www.livecoding.tv/accounts/login/");
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)";
request.CookieContainer = cookies;
request.Method = "POST";
request.Referer = "https://www.livecoding.tv/accounts/login/";
request.ContentType = "application/x-www-form-urlencoded";
postData.Add ("csrfmiddlewaretoken", HtmlHelper.getAttribute(HtmlHelper.getSingleElement(data,"<input type='hidden' name='csrfmiddlewaretoken'"),"value"));
postData.Add ("login", username);
postData.Add ("password", password);
byte[] postBuild = HttpHelper.CreatePostData (postData);
request.ContentLength = postBuild.Length;
request.GetRequestStream ().Write (postBuild, 0, postBuild.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse ();
using (System.IO.StreamReader sr = new System.IO.StreamReader (response.GetResponseStream ())) {
data = sr.ReadToEnd();
}
if (LoginCompleted != null)
LoginCompleted (this, cookies);
}
示例4: CreateRegex
static Regex lineSimpleApply = CreateRegex(@"^Ext.apply\(\s*(?<name>({id}\.)?{idx})(\.prototype)?.*"); // e.g. Ext.apply(Dextop.common, {
#endregion Fields
#region Methods
public override void ProcessFile(String filePath, Dictionary<String, LocalizableEntity> map)
{
ClasslikeEntity jsObject = null;
System.IO.TextReader reader = new System.IO.StreamReader(filePath, Encoding.UTF8);
//Logger.LogFormat("Processing file {0}", filePath);
try
{
while (reader.Peek() > 0)
{
String line = reader.ReadLine();
ClasslikeEntity o = ProcessExtendLine(filePath, line);
if (o != null)
jsObject = o;
else if (jsObject != null) {
LocalizableEntity prop = ProcessPropertyLine(jsObject, line);
if (prop != null && !map.ContainsKey(prop.FullEntityPath))
map.Add(prop.FullEntityPath, prop);
}
}
Logger.LogFormat("Processing file {0} - Success", filePath);
}
catch (Exception ex)
{
Logger.LogFormat("Processing file {0} - Error", filePath);
throw ex;
}
finally
{
reader.Close();
}
}
示例5: ExtractSettingsFromFile
public bool ExtractSettingsFromFile(String pathFileSettings)
{
try
{
if (System.IO.File.Exists(pathFileSettings) == true)
{
System.IO.StreamReader myFile = new System.IO.StreamReader(pathFileSettings);
string globalContent = myFile.ReadToEnd();
myFile.Close();
if (globalContent.Contains(LineFileSeparator))
{
String[] listSettings = globalContent.Split(LineFileSeparator.ToCharArray());
for (int indexString = 0; indexString < listSettings.Length; indexString++)
{
if (listSettings[indexString].Contains(charToRemove.ToString()))
{
listSettings[indexString] = listSettings[indexString].Remove(listSettings[indexString].IndexOf(charToRemove), 1);
}
}
return ProcessSettings(listSettings);
}
}
return false;
}
catch (Exception)
{
return false;
}
}
示例6: Button1_Click
private void Button1_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
System.IO.StreamReader OpenFile = new System.IO.StreamReader(openFileDialog1.FileName);
txtphoto.Text = openFileDialog1.FileName;
OpenFile.Close();
}
示例7: LoadSampleData
static void LoadSampleData()
{
int counter = 0;
string line;
IHttpClient client = new HttpClient();
// Simple data import operation
using (System.IO.StreamReader file = new System.IO.StreamReader(@"C:\GitHub\iAFWeb\data\top-1m.csv"))
{
while ((line = file.ReadLine()) != null)
{
String[] values = line.Split(',');
if (values.Length == 2)
{
string url = String.Format("http://{0}", values[1]);
Uri uri;
if(Uri.TryCreate(url, UriKind.Absolute, out uri))
{
var response = client.Shorten(uri.ToString());
Console.WriteLine(counter + " : " + response.ShortId + " : " + uri.ToString());
counter++;
}
}
}
}
// Suspend the screen.
Console.ReadLine();
}
示例8: Get
/// <summary>
/// 发送Get请求
/// </summary>
/// <param name="url">请求地址</param>
/// <returns></returns>
public string Get(string url)
{
//System.Net.ServicePointManager.DefaultConnectionLimit = 512;
//int i = System.Net.ServicePointManager.DefaultPersistentConnectionLimit;
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";
request.Accept = "*/*";
request.Timeout = 20000;
request.AllowAutoRedirect = false;
request.ServicePoint.Expect100Continue = false;
try
{
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
if (response.StatusCode == HttpStatusCode.OK)
{
using (System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
return reader.ReadToEnd();
}
}
else
return response.StatusDescription;
}
catch(Exception e)
{
return e.Message;
}
finally
{
request = null;
}
}
示例9: HttpGet
public static string HttpGet(string URI)
{
System.Net.WebRequest req = System.Net.WebRequest.Create(URI);
System.Net.WebResponse resp = req.GetResponse();
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
return sr.ReadToEnd().Trim();
}
示例10: Parse
/* ----------------------------------------------------------------- */
// Parse
/* ----------------------------------------------------------------- */
public Container.Dictionary<string, string> Parse(string product, string version, bool init)
{
Container.Dictionary<string, string> dest = null;
var uri = "http://" + host_ + "/" + product + "/update.php?ver=" + System.Web.HttpUtility.UrlEncode(version);
if (init) uri += "&flag=install";
var request = System.Net.WebRequest.Create(uri);
using (var response = request.GetResponse()) {
using (var input = response.GetResponseStream()) {
string line = "";
var reader = new System.IO.StreamReader(input, System.Text.Encoding.GetEncoding("UTF-8"));
while ((line = reader.ReadLine()) != null) {
if (line.Length > 0 && line[0] == '[' && line[line.Length - 1] == ']') {
var version_cmp = line.Substring(1, line.Length - 2);
if (version_cmp == version) {
dest = ExecParse(reader);
break;
}
}
}
}
}
return dest;
}
示例11: OtherWaysToGetReport
private static void OtherWaysToGetReport()
{
string report = @"d:\bla.rdl";
// string lalal = System.IO.File.ReadAllText(report);
// byte[] foo = System.Text.Encoding.UTF8.GetBytes(lalal);
// byte[] foo = System.IO.File.ReadAllBytes(report);
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
using (System.IO.FileStream file = new System.IO.FileStream(report, System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
byte[] bytes = new byte[file.Length];
file.Read(bytes, 0, (int)file.Length);
ms.Write(bytes, 0, (int)file.Length);
ms.Flush();
ms.Position = 0;
}
using (System.IO.Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("resource"))
{
using (System.IO.TextReader reader = new System.IO.StreamReader(ms))
{
// rv.LocalReport.LoadReportDefinition(reader);
}
}
using (System.IO.TextReader reader = System.IO.File.OpenText(report))
{
// rv.LocalReport.LoadReportDefinition(reader);
}
}
}
示例12: ExecuteCmdlet
protected override void ExecuteCmdlet()
{
WebPartEntity wp = null;
if (ParameterSetName == "FILE")
{
if (System.IO.File.Exists(Path))
{
System.IO.StreamReader fileStream = new System.IO.StreamReader(Path);
string webPartString = fileStream.ReadToEnd();
fileStream.Close();
wp = new WebPartEntity();
wp.WebPartZone = ZoneId;
wp.WebPartIndex = ZoneIndex;
wp.WebPartXml = webPartString;
}
}
else if (ParameterSetName == "XML")
{
wp = new WebPartEntity();
wp.WebPartZone = ZoneId;
wp.WebPartIndex = ZoneIndex;
wp.WebPartXml = Xml;
}
if (wp != null)
{
this.SelectedWeb.AddWebPartToWebPartPage(PageUrl, wp);
}
}
示例13: LoadMove
public static Move LoadMove(int moveNum)
{
Move move = new Move();
string[] parse = null;
using (System.IO.StreamReader read = new System.IO.StreamReader(IO.Paths.MovesFolder + "move" + moveNum + ".dat")) {
while (!(read.EndOfStream)) {
parse = read.ReadLine().Split('|');
switch (parse[0].ToLower()) {
case "movedata":
if (parse[1].ToLower() != "v4") {
read.Close();
return null;
}
break;
case "data":
move.Name = parse[1];
move.MaxPP = parse[2].ToInt();
move.EffectType = (Enums.MoveType)parse[3].ToInt();
move.Element = (Enums.PokemonType)parse[4].ToInt();
move.MoveCategory = (Enums.MoveCategory)parse[5].ToInt();
move.RangeType = (Enums.MoveRange)parse[6].ToInt();
move.Range = parse[7].ToInt();
move.TargetType = (Enums.MoveTarget)parse[8].ToInt();
move.Data1 = parse[9].ToInt();
move.Data2 = parse[10].ToInt();
move.Data3 = parse[11].ToInt();
move.Accuracy = parse[12].ToInt();
move.HitTime = parse[13].ToInt();
move.AdditionalEffectData1 = parse[14].ToInt();
move.AdditionalEffectData2 = parse[15].ToInt();
move.AdditionalEffectData3 = parse[16].ToInt();
move.PerPlayer = parse[17].ToBool();
move.KeyItem = parse[18].ToInt();
move.Sound = parse[19].ToInt();
move.AttackerAnim.AnimationType = (Enums.MoveAnimationType)parse[20].ToInt();
move.AttackerAnim.AnimationIndex = parse[21].ToInt();
move.AttackerAnim.FrameSpeed = parse[22].ToInt();
move.AttackerAnim.Repetitions = parse[23].ToInt();
move.TravelingAnim.AnimationType = (Enums.MoveAnimationType)parse[24].ToInt();
move.TravelingAnim.AnimationIndex = parse[25].ToInt();
move.TravelingAnim.FrameSpeed = parse[26].ToInt();
move.TravelingAnim.Repetitions = parse[27].ToInt();
move.DefenderAnim.AnimationType = (Enums.MoveAnimationType)parse[28].ToInt();
move.DefenderAnim.AnimationIndex = parse[29].ToInt();
move.DefenderAnim.FrameSpeed = parse[30].ToInt();
move.DefenderAnim.Repetitions = parse[31].ToInt();
break;
}
}
}
return move;
}
示例14: setLock
public void setLock(Event.Event evt,int cctvid,string desc1,string desc2,int preset)
{
try
{
unlock();
this.cctvid=cctvid;
this.desc1=desc1;
this.desc2=desc2;
this.preset=preset;
this.evt = evt;
byte[] codebig5 =/* RemoteInterface.Util.StringToUTF8Bytes(desc2);*/ RemoteInterface.Util.StringToBig5Bytes(desc2);
desc2 = System.Web.HttpUtility.UrlEncode(codebig5);
codebig5 = /* RemoteInterface.Util.StringToUTF8Bytes(desc1); */ RemoteInterface.Util.StringToBig5Bytes(desc1);
desc1 = System.Web.HttpUtility.UrlEncode(codebig5);
string uristr=string.Format(LockWindows.lockurlbase,this.wid,this.cctvid,desc1,desc2,preset);
// string uristr = string.Format(LockWindows.lockurlbase, 3, this.cctvid, desc1, desc2, preset);
//只鎖定 第3號視窗
System.Net.WebRequest web = System.Net.HttpWebRequest.Create(new Uri(uristr
,UriKind.Absolute)
);
System.IO.Stream stream = web.GetResponse().GetResponseStream();
System.IO.StreamReader rd = new System.IO.StreamReader(stream);
string res = rd.ReadToEnd();
isLock = true;
}
catch (Exception ex)
{
isLock = false;
}
}
示例15: parseBiografia
private void parseBiografia()
{
string line;
char[] delimiterChars1 = { ':' };
char[] delimiterChars2 = { '.' };
List<String> lista = new List<String>();
int BIO_ESTADO_INDEX = 0;
// Read the file and display it line by line.
System.IO.StreamReader file = new System.IO.StreamReader(Biografia);
while ((line = file.ReadLine()) != null && BIO_ESTADO_INDEX < BioEstado)
{
string[] words = line.Split(delimiterChars1);
if (words[0].Contains("P"))
{
string[] numbers = words[0].Split(delimiterChars2);
this.ParagrafosBiografia.Add(Int32.Parse(numbers[0]), words[2]);
}
BIO_ESTADO_INDEX++;
}
file.Close();
}