本文整理汇总了C#中StreamReader.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# StreamReader.Dispose方法的具体用法?C# StreamReader.Dispose怎么用?C# StreamReader.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StreamReader
的用法示例。
在下文中一共展示了StreamReader.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
fileUrl = Server.MapPath(".") + "\\patch_Data\\update.sql";
bool done = bool.Parse(Setup.Patch.Get("db_updated"));
btnRunSQL.Enabled = !done;
lblDBCreation.Visible = done;
lnkNext.Visible = done;
if (!done)
{
string templateUrl = Server.MapPath(".") + "\\patch_Data\\update_template.sql";
StreamReader sr = new StreamReader(templateUrl);
StreamWriter sw = new StreamWriter(fileUrl, false);
try
{
dbDataContext db = new dbDataContext();
int first_group = db.sub_units.First().id;
while (!sr.EndOfStream)
sw.WriteLine(sr.ReadLine().Replace("_REPLACE_", first_group.ToString()));
}
catch (Exception ex)
{
lblOutput.Text = "An error occured: " + ex.ToString();
lblOutput.CssClass = "error";
}
finally
{
sr.Close(); sr.Dispose();
sw.Close(); sw.Dispose();
}
}
}
示例2: AsString
public static string AsString(string path)
{
StreamReader streamReader = null;
Stream stream = null;
string value;
try
{
stream = assembly.GetManifestResourceStream(path);
if (stream == null)
{
var message = string.Concat("Could not find a resource named '", path,"'.");
throw new Exception(message);
}
streamReader = new StreamReader(stream);
value = streamReader.ReadToEnd();
}
finally
{
if (streamReader != null)
{
streamReader.Dispose();
}
if (stream != null)
{
stream.Dispose();
}
}
return value;
}
示例3: Main
static void Main()
{
string fileName = "file.xml";
StreamReader streamReader = new StreamReader(fileName,Encoding.GetEncoding("windows-1251"));
string text = streamReader.ReadToEnd();
streamReader.Dispose();
int indexleft = text.IndexOf('>',0);
int indexRight = text.IndexOf('<', indexleft);
List<string> words = new List<string>();
while (indexleft != -1 && indexRight != -1)
{
if (indexRight != -1 && indexRight != indexleft + 1)
{
words.Add(text.Substring(indexleft + 1, indexRight - indexleft - 1).Trim());
}
indexleft++;
indexleft = text.IndexOf('>', indexleft);
indexRight = text.IndexOf('<', indexleft);
}
for (int i = 0; i < words.Count; i++)
{
if (words[i] == "")
{
words.Remove(words[i]);
i--;
}
else
{
Console.WriteLine(words[i]);
}
}
}
示例4: CKEditor1_DataBinding
protected void CKEditor1_DataBinding(object sender, EventArgs e)
{
if ((bool)ViewState["OpeningEditor"] == false)//To Load Data Into Editor
return;
ViewState["OpeningEditor"] = false;
try
{
CKEditor.NET.CKEditorControl MyEditor = (CKEditor.NET.CKEditorControl)sender;
DataRowView row = (DataRowView)GVEditor.GetRow(GVEditor.FocusedRowIndex);
if (Home_WorkCodes.IsNullOrEmpty(row["id"]))
return;
string FilePath = MapPath(FilesPath + row["id"]);
if (File.Exists(FilePath))
{
TextReader TR = new StreamReader(FilePath);
string tt = TR.ReadToEnd().ToString();
TR.Close();
TR.Dispose();
MyEditor.Text = tt;
}
}
catch
{ }
}
示例5: LoadPage
public string LoadPage()
{
string Path = string.Empty;
OleDbDataAdapter da = new OleDbDataAdapter("SELECT Data_Path FROM RotatorData Where ID = " + DDLItems.SelectedValue, constr);
DataTable dt = new DataTable();
try
{
da.Fill(dt);
if (dt.Rows.Count > 0)
{
Path = dt.Rows[0]["Data_Path"].ToString();
}
}
catch { }
if (Path == string.Empty)
{
//HtmlEditorQA.Html = string.Empty;
return string.Empty;
}
Path = MapPath(Path);
if (!File.Exists(Path))
{
return string.Empty;
}
else
{
TextReader TR = new StreamReader(Path);
string tt = TR.ReadToEnd().ToString();
TR.Close();
TR.Dispose();
return tt;
}
}
示例6: LoadPage
public string LoadPage()
{
string Path = string.Empty;
OleDbConnection Con = new OleDbConnection(constr);
OleDbCommand CMD = new OleDbCommand("SELECT Contain FROM NewsData Where ID = " + Request.QueryString["ID"].ToString(), Con);
try
{
Con.Open();
Path = CMD.ExecuteScalar().ToString();
}
catch { }
Con.Close();
if (Path == string.Empty)
{
//HtmlEditorQA.Html = string.Empty;
return string.Empty;
}
Path = MapPath(Path);
if (!File.Exists(Path))
{
return string.Empty;
}
else
{
TextReader TR = new StreamReader(Path);
string tt = TR.ReadToEnd().ToString();
TR.Close();
TR.Dispose();
return tt;
}
}
示例7: SendHTMLMail
// Method Which is used to Get HTML File and replace HTML File values with dynamic values and send mail
public void SendHTMLMail()
{
StreamReader reader = new StreamReader(Server.MapPath("~/HTMLPage.htm"));
string readFile = reader.ReadToEnd();
string myString = "";
myString = readFile;
myString = myString.Replace("$$Admin$$", "Suresh Dasari");
myString = myString.Replace("$$CompanyName$$", "Dasari Group");
myString = myString.Replace("$$Email$$", "[email protected]");
myString = myString.Replace("$$Website$$", "http://www.aspdotnet-suresh.com");
MailMessage Msg = new MailMessage();
MailAddress fromMail = new MailAddress("[email protected]");
// Sender e-mail address.
Msg.From = fromMail;
// Recipient e-mail address.
Msg.To.Add(new MailAddress("[email protected]"));
// Subject of e-mail
Msg.Subject = "Send Mail with HTML File";
Msg.Body = myString.ToString();
Msg.IsBodyHtml = true;
string sSmtpServer = "";
sSmtpServer = "10.2.69.121";
SmtpClient a = new SmtpClient();
a.Host = sSmtpServer;
a.Send(Msg);
reader.Dispose();
}
示例8: SampleWSPost
public static void SampleWSPost(SqlString weburl, out SqlString returnval)
{
string url = Convert.ToString(weburl);
string feedData = string.Empty;
try {
HttpWebRequest request = null;
HttpWebResponse response = null;
Stream stream = null;
StreamReader streamReader = null;
request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
response = (HttpWebResponse)request.GetResponse();
stream = response.GetResponseStream();
streamReader = new StreamReader(stream);
feedData = streamReader.ReadToEnd();
response.Close();
stream.Dispose();
streamReader.Dispose();
} catch (Exception ex) {
SqlContext.Pipe.Send(ex.Message.ToString());
}
returnval = feedData;
}
示例9: LoadPage
public string LoadPage()
{
string Path = string.Empty;
OleDbConnection Con = new OleDbConnection(constr);
OleDbCommand CMD = new OleDbCommand("SELECT Data_Path FROM MenuItem Where ItemID = " + MainMenu.SelectedValue.ToString(), Con);
try
{
Con.Open();
Path = CMD.ExecuteScalar().ToString();
}
catch { }
Con.Close();
if (Path == string.Empty)
{
//HtmlEditorQA.Html = string.Empty;
return string.Empty;
}
Path = MapPath(Path);
if (!File.Exists(Path))
{
return string.Empty;
}
else
{
TextReader TR = new StreamReader(Path);
string tt = TR.ReadToEnd().ToString();
TR.Close();
TR.Dispose();
return tt;
}
}
示例10: AdminiBalance
protected void AdminiBalance()
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.payintegra.com/PartnerBalance");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
string postData = "PartnerId=10118&Hash=428EC1E88E87E1FEADB2F8FFBD2260E7C8FEDB3B";
byte[] bytes = Encoding.UTF8.GetBytes(postData);
request.ContentLength = bytes.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
var result = reader.ReadToEnd();
Session["FinalAdminBalance"] = result;
stream.Dispose();
reader.Dispose();
}
catch (Exception ex)
{
throw ex;
}
}
示例11: downloadFTPFiles
public static int downloadFTPFiles(string ftpsite, string filter, string downloadpath)
{
string ftpfile = "";
int cnt = 0;
StreamReader read = null;
FtpWebRequest fareq = (FtpWebRequest)WebRequest.Create(ftpsite);
fareq.Method = WebRequestMethods.Ftp.DownloadFile;
fareq.Method = WebRequestMethods.Ftp.ListDirectory;
FtpWebResponse resp = (FtpWebResponse)fareq.GetResponse();
read = new StreamReader(resp.GetResponseStream());
string ln = read.ReadLine();
while (ln != null)
{
if (ln.Contains(filter) == true)
{
ftpfile = ftpsite + ln;
using (WebClient wbc = new WebClient())
{
string newdo = downloadpath + ln;
wbc.DownloadFile(ftpfile, newdo);
}
}
ln = read.ReadLine();
}
read.Close();
read.Dispose();
return cnt;
}
示例12: Main
static void Main()
{
string fileName = "matrix.txt";
StreamReader streamReader = new StreamReader(fileName);
int length = int.Parse(streamReader.ReadLine());
int[,] array = new int[length, length];
for (int i = 0; i < array.GetLength(0); i++)
{
string[] line = streamReader.ReadLine().Split(' ');
for (int j = 0; j < array.GetLength(1); j++)
{
array[i, j] = int.Parse(line[j]);
}
}
streamReader.Dispose();
int bestSum = int.MinValue;
for (int i = 0; i < array.GetLength(0) - 1; i++)
{
for (int j = 0; j < array.GetLength(1) - 1; j++)
{
int currentSum = array[i, j] + array[i, j + 1] + array[i + 1, j] + array[i + 1, j + 1];
if (currentSum > bestSum)
{
bestSum = currentSum;
}
}
}
string resultFileName = "result.txt";
StreamWriter streamWriter = new StreamWriter(resultFileName);
streamWriter.Write(bestSum);
streamWriter.Dispose();
}
示例13: LoadContain
public string LoadContain()
{
if (Request.QueryString["CourseId"] == null)
{
return string.Empty;
}
string ThePath = string.Empty;
string RetData = string.Empty;
using (OleDbConnection Con = new OleDbConnection(constr))
{
OleDbCommand cmd = new OleDbCommand(String.Format("SELECT TOP 1 DataPath FROM CoursenotimeDataPath WHERE CourseId = {0}", Request.QueryString["CourseId"]), Con);
try
{
Con.Open();
ThePath = cmd.ExecuteScalar().ToString();
//if (ThePath != string.Empty)
// ThePath = MapPath(DB.CourseNoTimeFileDir + ThePath);
ThePath = DB.CourseNoTimeFileDir + ThePath;
TextReader TR = new StreamReader(ThePath);
RetData = TR.ReadToEnd();
TR.Close();
TR.Dispose();
}
catch (Exception ex)
{
RetData = ex.Message;
}
Con.Close();
}
return HttpUtility.HtmlDecode(RetData);
}
示例14: LoadContain
public string LoadContain()
{
bool Path2nd = false;
if (Request.QueryString["id"] == null)
{
return string.Empty;
}
if (Request.QueryString["Path2nd"] == null)
Path2nd = false;
else
Path2nd = true;// Show 2nd Path
string Path = string.Empty;
string Path2 = string.Empty;
string RetData = string.Empty;
using (OleDbConnection Con = new OleDbConnection(constr))
{
OleDbDataAdapter da = new OleDbDataAdapter(String.Format("SELECT Data_Path, Data_Path2 FROM MenuItem WHERE (ItemID = {0})", Request.QueryString["id"]), constr);
DataTable dt = new DataTable();
try
{
da.Fill(dt);
if (dt.Rows.Count > 0)
{
Path = dt.Rows[0]["Data_Path"].ToString();
Path2 = dt.Rows[0]["Data_Path2"].ToString();
}
if (Path2nd)
{
if (Path2 != string.Empty)
Path2 = MapPath(Path2);
if (File.Exists(Path2))
{
TextReader TR = new StreamReader(Path2);
RetData = TR.ReadToEnd();
TR.Close();
TR.Dispose();
}
}
else
{
if (Path != string.Empty)
Path = MapPath(Path);
if (File.Exists(Path))
{
TextReader TR = new StreamReader(Path);
RetData = TR.ReadToEnd();
TR.Close();
TR.Dispose();
}
}
}
catch (Exception ex)
{
RetData = ex.Message;
}
Con.Close();
}
return HttpUtility.HtmlDecode(RetData);
}
示例15: readFileMethod4
public static void readFileMethod4(string fn)
{
StreamReader sr = new StreamReader(fn);
string content = sr.ReadToEnd();
Console.WriteLine(content);
sr.Close();
// You should call Dispose on 'reader' here, too.
sr.Dispose();
}