ASP. NET read TXT file (Notepad) content:
using System;
Using System.Collections;
Using System.Configuration;
Using System.Data;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.HtmlControls;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.IO; Get TXT file stream nam
(1) reading files
If you want to read not many files, you can use file. readalltext (filepath) or specify the encoding method file. readalltext (filepath, encoding. They read all the text content at a time and return a string containing all the text content.
StringSTR = file. readalltext (@ "C: \ temp \ ascii.txt");// You can specify the encoding method.StringStr2 = file. readalltext (@ "C: \ temp \ ascii.txt", Encoding. ASCII );
You can also use file. readalllines. This method returns a
It is easy to use ASP. NET to output documents of the Word, Excel, txt, htm, and other types of specified content. It can be completed in three steps.
1. Define document type and character encoding
Response. Clear ();Response. Buffer = true;Response. charset = "UTF-8 ";
// The following line is very important. The attachment parameter indicates downloading as an attachment. You can change it to onli
ASP. net for txt file-related operations (read, write, save), asp. nettxt
ASP. NET reads the txt file (Notepad) content:
Using System; using System. collections; using System. configuration; using System. data; using System. web; using System. web. security; using System. web. UI; using System. web. UI. htmlControls; u
The following to achieve this function is to use asp.net based on the data content to automatically generate a TXT text file and provide users to download, this method file does not exist on the server, directly provided to the user to download, to the online search, are used Response.BinaryWrite (), with a few, Found that there is a problem in IE, look at the page source code data is out, Firefox is a pop-up box to download, but not
Method codeMemoryStream ms = new MemoryStream ();byte[] buffer = NULL;using (ZipFile file = Zipfile.create (ms)){File. BeginUpdate ();File. Nametransform = new Mynametransfom ();//Through this name formatter, you can do some processing of the file name inside. By default, the relevant folder is created automatically based on the path of the file in the zip.File. ADD (Server.MapPath ("~/1.txt"));File. ADD (Server.MapPath ("~/1.
It is easy to use ASP. NET to output documents of the Word, Excel, txt, htm, and other types of specified content.
Call the following method in the page_load event:
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
1
Private
Void
Puttoword ()
2
{ 3 Response. Clear (); 4 Response. Buffer = True ; 5 Response. charset = " UT
In fact, it is easy to use ASP. NET to output documents of the Word, Excel, txt, htm, and other types of specified content. It can be completed in three steps.
1. Define document type and character encoding
Response. Clear ();Response. Buffer = true;Response. charset = "UTF-8 ";
// The following line is very important. The attachment parameter indicates downloading as an attachment. You can change it
Today, when I browsed the forum, I saw another topic about reading TXT text files. Insus. NET also wants to implement it based on its own ideas and share it with you.Text files are complex, and retrieving data is also part of some text lines. To get more accurate data, Insus. NET writes several steps. Each step uses a class. After all, the program we write is obj
When performing some bulk operations, it is easier and more convenient to record some execution log information.Provides a common and simple way to record information in a TXT file: Public Static voidLogstringContentstringpath) { stringstrFileName =path; //determine if there is if(File.exists (strFileName)) {//existStreamWriter Wlog; Wlog=File.appendtext (strFileName); Wlog. Write ("\r\n{0}", content); Wlog. Flush
[ASP. NET advanced] scheduled execution of tasks (regularly reading and modifying txt file numeric content without refreshing new display results), asp. nettxt
There are many websites or systems that need to do something regularly on the server, such as clearing invalid data in the database at half past eight every morning. The Demo implementation steps are as follows:
0. first look at the solution
1. Crea
In fact, it is easy to use ASP. NET to output documents of the Word, Excel, txt, htm, and other types of specified content. It can be completed in three steps.
1. Define document type and character encoding
Response. Clear ();Response. Buffer = true;Response. charset = "UTF-8 ";
// The following line is very important. The attachment parameter indicates downloading as an attachment. You can change i
","attachment;filename="+fileinfo.name); -Response.AddHeader ("Content-length", fileInfo.Length.ToString ()); -Response.AddHeader ("content-transfer-encoding","binary"); the //tell the browser to pass to the user is a non-txt,rar, etc. does not appear on the Ieem of a file, do not need to open in the browser page, need to download directly -Response.ContentType ="Application/octet-stream"; -response.contentencoding = System.Text.Encodi
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.