"Reprinted" to learn how to operate file streams in ASP. NET
Author: anytao
Introduction:
In web development, operations on files are often performed.ProgramOne of the necessary lessons for design. Improving ASP. NET design capabilities, handling the use of controls, database operations, XML technology, and reading and writing files is also one of the secrets to improve web design and development.
This article uses a simple example to explain how to read text information on a web page to implement the ability to change the background of pages that do not often update information, because the information is not often updated, for example, there is no need to implement pages, website introductions, and website maps in the form of databases. The design complexity and system overhead are unnecessary.
Basic Information
Development Environment: vs2003 tool,. NET platform, C # Language
Key Technical Points: Reading and Writing of file streams in ASP. NET, dynamic use of table controls
Solution
1 worker. For the benefits, seeCode.
2. Add Table and set its style.
3. In page_load (), add the code implementation for loading text information.
1 private void page_load (Object sender, system. eventargs E)
2 {
3 // place user code here to initialize the page
4 // read the file path
5 string filenameurl = server. mappath (@ "blogtext \ url.txt ");
6 string filenamelnk = server. mappath (@ "blogtext \ link.txt ");
7
8 // read the text file to the file stream
9 streamreader srurl = new streamreader (filenameurl );
10 streamreader srlnk = new streamreader (filenamelnk );
11
12 string strurl, strlnk;
13
14 While (srurl. Peek ()! =-1)
15 {
16 strurl = srurl. Readline ();
17 strlnk = srlnk. Readline ();
18
19 // use two text files to easily separate URL and text
20 hyperlink hlnk = new hyperlink ();
21 hlnk. Visible = true;
22 hlnk. Text = strurl;
23 hlnk. navigateurl = strurl;
24
25 // other methods can be used for dynamic implementation
26 // Add text information to the table dynamically
27 tablerow TR = new tablerow ();
28 tablecell TC1 = new tablecell ();
29 tablecell TC2 = new tablecell ();
30
31 tc1.text = strlnk;
32 tc2.controls. Add (hlnk );
33 tr. cells. Add (TC1 );
34 tr. cells. Add (TC2 );
35 tabtext. Rows. Add (TR );
36
37}
38
39}
40
4. Run and check. OK.
Conclusion
File operations are the basic content of program development and need to be further improved. In the example in this article, you can try to use dataset and XML to implement it, which is more flexible. The specific ideas can be further explored.
I hope you will join the bricks and eggs, and I will try my best to move forward in the storm.
Enjoy.
About the author
After several years of learning, I woke up with technology and thought about the world. Internal focus on. NET, external discussion on Delphi, only in Beijing, full funding. By virtue of the column, the mission is to establish an industry-based preaching, and to learn from all corners of the world, and to cultivate the technology of China.
Stay tuned to anytao.com.