﻿{"id":605,"date":"2010-01-15T01:12:00","date_gmt":"2010-01-14T17:12:00","guid":{"rendered":"http:\/\/blog.jixin.ntxz.net\/?p=605"},"modified":"2010-07-30T15:40:40","modified_gmt":"2010-07-30T07:40:40","slug":"c%e4%bd%9ctxt","status":"publish","type":"post","link":"http:\/\/www.ntxz.net\/?p=605","title":{"rendered":"c#***\u4f5ctxt"},"content":{"rendered":"<p>C#\u8ffd\u52a0\u6587\u4ef6 <br \/>StreamWriter sw = File.AppendText(Server.MapPath(&#8220;.&#8221;)+&#8221;<a href=\"http:\/\/blog.cnbytes.net\/file:\/\/\/\"><font color=#005880>\\\\myText.txt<\/font><\/a>&#8220;); <br \/>sw.WriteLine(&#8220;\u8ffd\u9010\u7406\u60f3&#8221;); <br \/>sw.WriteLine(&#8220;kzlll&#8221;); <br \/>sw.WriteLine(&#8220;.NET\u7b14\u8bb0&#8221;); <br \/>sw.Flush(); <br \/>sw.Close(); <\/p>\n<p>C#\u62f7\u8d1d\u6587\u4ef6 <br \/>string OrignFile,NewFile; <br \/>OrignFile = Server.MapPath(&#8220;.&#8221;)+&#8221;<a href=\"http:\/\/blog.cnbytes.net\/file:\/\/\/\"><font color=#005880>\\\\myText.txt<\/font><\/a>&#8220;; <br \/>NewFile = Server.MapPath(&#8220;.&#8221;)+&#8221;<a href=\"http:\/\/blog.cnbytes.net\/file:\/\/\/\"><font color=#005880>\\\\myTextCopy.txt<\/font><\/a>&#8220;; <br \/>File.Copy(OrignFile,NewFile,true);<\/p>\n<p>C#\u5220\u9664\u6587\u4ef6 <br \/>string delFile = Server.MapPath(&#8220;.&#8221;)+&#8221;<a href=\"http:\/\/blog.cnbytes.net\/file:\/\/\/\"><font color=#005880>\\\\myTextCopy.txt<\/font><\/a>&#8220;; <br \/>File.Delete(delFile);<\/p>\n<p>C#\u79fb\u52a8\u6587\u4ef6 <br \/>string OrignFile,NewFile; <br \/>OrignFile = Server.MapPath(&#8220;.&#8221;)+&#8221;<a href=\"http:\/\/blog.cnbytes.net\/file:\/\/\/\"><font color=#005880>\\\\myText.txt<\/font><\/a>&#8220;; <br \/>NewFile = Server.MapPath(&#8220;.&#8221;)+&#8221;<a href=\"http:\/\/blog.cnbytes.net\/file:\/\/\/\"><font color=#005880>\\\\myTextCopy.txt<\/font><\/a>&#8220;; <br \/>File.Move(OrignFile,NewFile);<\/p>\n<p>C#\u521b\u5efa\u76ee\u5f55 <br \/>\/\/ \u521b\u5efa\u76ee\u5f55c:\\sixAge <br \/>DirectoryInfo d=Directory.CreateDirectory(&#8220;c:\\\\sixAge&#8221;); <br \/>\/\/ d1\u6307\u5411c:\\sixAge\\sixAge1 <br \/>DirectoryInfo d1=d.CreateSubdirectory(&#8220;sixAge1&#8221;); <br \/>\/\/ d2\u6307\u5411c:\\sixAge\\sixAge1\\sixAge1_1 <br \/>DirectoryInfo d2=d1.CreateSubdirectory(&#8220;sixAge1_1&#8221;); <br \/>\/\/ \u5c06\u5f53\u524d\u76ee\u5f55\u8bbe\u4e3ac:\\sixAge <br \/>Directory.SetCurrentDirectory(&#8220;c:\\\\sixAge&#8221;); <br \/>\/\/ \u521b\u5efa\u76ee\u5f55c:\\sixAge\\sixAge2 <br \/>Directory.CreateDirectory(&#8220;sixAge2&#8221;); <br \/>\/\/ \u521b\u5efa\u76ee\u5f55c:\\sixAge\\sixAge2\\sixAge2_1 <br \/>Directory.CreateDirectory(&#8220;sixAge2\\\\sixAge2_1&#8221;);<\/p>\n<p>\u9012\u5f52\u5220\u9664\u6587\u4ef6\u5939\u53ca\u6587\u4ef6 <br \/>&lt;%@ Page Language=C#%&gt; <br \/>&lt;%@ Import namespace=&#8221;System.IO&#8221;%&gt; <br \/>&lt;Script runat=server&gt; <br \/>public void DeleteFolder(string dir) <br \/>{ <br \/>&nbsp;&nbsp;&nbsp; if (Directory.Exists(dir)) \/\/\u5982\u679c\u5b58\u5728\u8fd9\u4e2a\u6587\u4ef6\u5939\u5220\u9664\u4e4b <br \/>&nbsp;&nbsp;&nbsp; { <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach(string d in Directory.GetFileSystemEntries(dir)) <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(File.Exists(d)) <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; File.Delete(d); \/\/\u76f4\u63a5\u5220\u9664\u5176\u4e2d\u7684\u6587\u4ef6 <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DeleteFolder(d); \/\/\u9012\u5f52\u5220\u9664\u5b50\u6587\u4ef6\u5939 <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Directory.Delete(dir); \/\/\u5220\u9664\u5df2\u7a7a\u6587\u4ef6\u5939 <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Write(dir+&#8221; \u6587\u4ef6\u5939\u5220\u9664\u6210\u529f&#8221;); <br \/>&nbsp;&nbsp;&nbsp; } <br \/>&nbsp;&nbsp;&nbsp; else <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Write(dir+&#8221; \u8be5\u6587\u4ef6\u5939\u4e0d\u5b58\u5728&#8221;); \/\/\u5982\u679c\u6587\u4ef6\u5939\u4e0d\u5b58\u5728\u5219\u63d0\u793a <br \/>}<\/p>\n<p>protected void Page_Load (Object sender ,EventArgs e) <br \/>{ <br \/>&nbsp;&nbsp;&nbsp; string Dir=&#8221;D:\\\\gbook\\\\11&#8243;; <br \/>&nbsp;&nbsp;&nbsp; DeleteFolder(Dir); \/\/\u8c03\u7528\u51fd\u6570\u5220\u9664\u6587\u4ef6\u5939 <br \/>}<\/p>\n<p>\/\/ ======================================================<br \/>\/\/ \u5b9e\u73b0\u4e00\u4e2a\u9759\u6001\u65b9\u6cd5\u5c06\u6307\u5b9a\u6587\u4ef6\u5939\u4e0b\u9762\u7684\u6240\u6709\u5185\u5bb9copy\u5230\u76ee\u6807\u6587\u4ef6\u5939\u4e0b\u9762<br \/>\/\/ \u5982\u679c\u76ee\u6807\u6587\u4ef6\u5939\u4e3a\u53ea\u8bfb\u5c5e\u6027\u5c31\u4f1a\u62a5\u9519\u3002<br \/>\/\/ April 18April2005 In STU<br \/>\/\/ ======================================================<br \/>public static void CopyDir(string srcPath,string aimPath)<br \/>{<br \/>&nbsp;&nbsp; try<br \/>&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp; \/\/ \u68c0\u67e5\u76ee\u6807\u76ee\u5f55\u662f\u5426\u4ee5\u76ee\u5f55\u5206\u5272\u5b57\u7b26\u7ed3\u675f\u5982\u679c\u4e0d\u662f\u5219\u6dfb\u52a0\u4e4b<br \/>&nbsp;&nbsp;&nbsp; if(aimPath[aimPath.Length-1] != Path.DirectorySeparatorChar) <br \/>&nbsp;&nbsp;&nbsp;&nbsp; aimPath += Path.DirectorySeparatorChar;<br \/>&nbsp;&nbsp;&nbsp; \/\/ \u5224\u65ad\u76ee\u6807\u76ee\u5f55\u662f\u5426\u5b58\u5728\u5982\u679c\u4e0d\u5b58\u5728\u5219\u65b0\u5efa\u4e4b<br \/>&nbsp;&nbsp;&nbsp; if(!Directory.Exists(aimPath)) Directory.CreateDirectory(aimPath);<br \/>&nbsp;&nbsp;&nbsp; \/\/ \u5f97\u5230\u6e90\u76ee\u5f55\u7684\u6587\u4ef6\u5217\u8868\uff0c\u8be5\u91cc\u9762\u662f\u5305\u542b\u6587\u4ef6\u4ee5\u53ca\u76ee\u5f55\u8def\u5f84\u7684\u4e00\u4e2a\u6570\u7ec4<br \/>&nbsp;&nbsp;&nbsp; \/\/ \u5982\u679c\u4f60\u6307\u5411copy\u76ee\u6807\u6587\u4ef6\u4e0b\u9762\u7684\u6587\u4ef6\u800c\u4e0d\u5305\u542b\u76ee\u5f55\u8bf7\u4f7f\u7528\u4e0b\u9762\u7684\u65b9\u6cd5<br \/>&nbsp;&nbsp;&nbsp; \/\/ string[] fileList = Directory.GetFiles(srcPath);<br \/>&nbsp;&nbsp;&nbsp; string[] fileList = Directory.GetFileSystemEntries(srcPath);<br \/>&nbsp;&nbsp;&nbsp; \/\/ \u904d\u5386\u6240\u6709\u7684\u6587\u4ef6\u548c\u76ee\u5f55<br \/>&nbsp;&nbsp;&nbsp; foreach(string file in fileList)<br \/>&nbsp;&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp;&nbsp; \/\/ \u5148\u5f53\u4f5c\u76ee\u5f55\u5904\u7406\u5982\u679c\u5b58\u5728\u8fd9\u4e2a\u76ee\u5f55\u5c31\u9012\u5f52Copy\u8be5\u76ee\u5f55\u4e0b\u9762\u7684\u6587\u4ef6<br \/>&nbsp;&nbsp;&nbsp;&nbsp; if(Directory.Exists(file))<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CopyDir(file,aimPath+Path.GetFileName(file));<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/ \u5426\u5219\u76f4\u63a5Copy\u6587\u4ef6<br \/>&nbsp;&nbsp;&nbsp;&nbsp; else<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; File.Copy(file,aimPath+Path.GetFileName(file),true);<br \/>&nbsp;&nbsp;&nbsp; }<br \/>&nbsp;&nbsp; }<br \/>&nbsp;&nbsp; catch (Exception e)<br \/>&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp; MessageBox.Show (e.ToString());<br \/>&nbsp;&nbsp; }<br \/>}<\/p>\n<p>\/\/ ======================================================<br \/>\/\/ \u5b9e\u73b0\u4e00\u4e2a\u9759\u6001\u65b9\u6cd5\u5c06\u6307\u5b9a\u6587\u4ef6\u5939\u4e0b\u9762\u7684\u6240\u6709\u5185\u5bb9Detele<br \/>\/\/ \u6d4b\u8bd5\u7684\u65f6\u5019\u8981\u5c0f\u5fc3***\u4f5c\uff0c\u5220\u9664\u4e4b\u540e\u65e0\u6cd5\u6062\u590d\u3002<br \/>\/\/ April 18April2005 In STU<br \/>\/\/ ======================================================<br \/>public static void DeleteDir(string aimPath)<br \/>{<br \/>&nbsp;&nbsp; try<br \/>&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp; \/\/ \u68c0\u67e5\u76ee\u6807\u76ee\u5f55\u662f\u5426\u4ee5\u76ee\u5f55\u5206\u5272\u5b57\u7b26\u7ed3\u675f\u5982\u679c\u4e0d\u662f\u5219\u6dfb\u52a0\u4e4b<br \/>&nbsp;&nbsp;&nbsp; if(aimPath[aimPath.Length-1] != Path.DirectorySeparatorChar) <br \/>&nbsp;&nbsp;&nbsp;&nbsp; aimPath += Path.DirectorySeparatorChar;<br \/>&nbsp;&nbsp;&nbsp; \/\/ \u5f97\u5230\u6e90\u76ee\u5f55\u7684\u6587\u4ef6\u5217\u8868\uff0c\u8be5\u91cc\u9762\u662f\u5305\u542b\u6587\u4ef6\u4ee5\u53ca\u76ee\u5f55\u8def\u5f84\u7684\u4e00\u4e2a\u6570\u7ec4<br \/>&nbsp;&nbsp;&nbsp; \/\/ \u5982\u679c\u4f60\u6307\u5411Delete\u76ee\u6807\u6587\u4ef6\u4e0b\u9762\u7684\u6587\u4ef6\u800c\u4e0d\u5305\u542b\u76ee\u5f55\u8bf7\u4f7f\u7528\u4e0b\u9762\u7684\u65b9\u6cd5<br \/>&nbsp;&nbsp;&nbsp; \/\/ string[] fileList = Directory.GetFiles(aimPath);<br \/>&nbsp;&nbsp;&nbsp; string[] fileList = Directory.GetFileSystemEntries(aimPath);<br \/>&nbsp;&nbsp;&nbsp; \/\/ \u904d\u5386\u6240\u6709\u7684\u6587\u4ef6\u548c\u76ee\u5f55<br \/>&nbsp;&nbsp;&nbsp; foreach(string file in fileList)<br \/>&nbsp;&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp;&nbsp; \/\/ \u5148\u5f53\u4f5c\u76ee\u5f55\u5904\u7406\u5982\u679c\u5b58\u5728\u8fd9\u4e2a\u76ee\u5f55\u5c31\u9012\u5f52Delete\u8be5\u76ee\u5f55\u4e0b\u9762\u7684\u6587\u4ef6<br \/>&nbsp;&nbsp;&nbsp;&nbsp; if(Directory.Exists(file))<br \/>&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DeleteDir(aimPath+Path.GetFileName(file));<br \/>&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/ \u5426\u5219\u76f4\u63a5Delete\u6587\u4ef6<br \/>&nbsp;&nbsp;&nbsp;&nbsp; else<br \/>&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; File.Delete (aimPath+Path.GetFileName(file));<br \/>&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>&nbsp;&nbsp;&nbsp; }<br \/>&nbsp;&nbsp;&nbsp; \/\/\u5220\u9664\u6587\u4ef6\u5939<br \/>&nbsp;&nbsp;&nbsp; System.IO .Directory .Delete (aimPath,true);<br \/>&nbsp;&nbsp; }<br \/>&nbsp;&nbsp; catch (Exception e)<br \/>&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp; MessageBox.Show (e.ToString());<br \/>&nbsp;&nbsp; }<br \/>}<\/p>\n<p>\u9700\u8981\u5f15\u7528\u547d\u540d\u7a7a\u95f4\uff1a<br \/>using System.IO;<\/p>\n<p>\/**\/\/\/\/ &lt;summary&gt;<br \/>\/\/\/ \u62f7\u8d1d\u6587\u4ef6\u5939(\u5305\u62ec\u5b50\u6587\u4ef6\u5939)\u5230\u6307\u5b9a\u6587\u4ef6\u5939\u4e0b,\u6e90\u6587\u4ef6\u5939\u548c\u76ee\u6807\u6587\u4ef6\u5939\u5747\u9700\u7edd\u5bf9\u8def\u5f84. \u683c\u5f0f: CopyFolder(\u6e90\u6587\u4ef6\u5939,\u76ee\u6807\u6587\u4ef6\u5939);<br \/>\/\/\/ &lt;\/summary&gt;<br \/>\/\/\/ &lt;param name=&#8221;strFromPath&#8221;&gt;&lt;\/param&gt;<br \/>\/\/\/ &lt;param name=&#8221;strToPath&#8221;&gt;&lt;\/param&gt;<\/p>\n<p>\/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\/\/\u4f5c\u8005:\u660e\u5929\u53bb\u8981\u996d QQ:305725744<br \/>\/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p>public static void CopyFolder(string strFromPath,string strToPath)<br \/>{<br \/>&nbsp;&nbsp; \/\/\u5982\u679c\u6e90\u6587\u4ef6\u5939\u4e0d\u5b58\u5728\uff0c\u5219\u521b\u5efa<br \/>&nbsp;&nbsp; if (!Directory.Exists(strFromPath))<br \/>&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp; Directory.CreateDirectory(strFromPath);<br \/>&nbsp;&nbsp; }&nbsp;&nbsp;<\/p>\n<p>&nbsp;&nbsp; \/\/\u53d6\u5f97\u8981\u62f7\u8d1d\u7684\u6587\u4ef6\u5939\u540d<br \/>&nbsp;&nbsp; string strFolderName = strFromPath.Substring(strFromPath.LastIndexOf(&#8220;\\\\&#8221;) + 1,strFromPath.Length &#8211; strFromPath.LastIndexOf(&#8220;\\\\&#8221;) &#8211; 1);&nbsp;&nbsp;<\/p>\n<p>&nbsp;&nbsp; \/\/\u5982\u679c\u76ee\u6807\u6587\u4ef6\u5939\u4e2d\u6ca1\u6709\u6e90\u6587\u4ef6\u5939\u5219\u5728\u76ee\u6807\u6587\u4ef6\u5939\u4e2d\u521b\u5efa\u6e90\u6587\u4ef6\u5939<br \/>&nbsp;&nbsp; if (!Directory.Exists(strToPath + &#8220;\\\\&#8221; + strFolderName))<br \/>&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp; Directory.CreateDirectory(strToPath + &#8220;\\\\&#8221; + strFolderName);<br \/>&nbsp;&nbsp; }<br \/>&nbsp;&nbsp; \/\/\u521b\u5efa\u6570\u7ec4\u4fdd\u5b58\u6e90\u6587\u4ef6\u5939\u4e0b\u7684\u6587\u4ef6\u540d<br \/>&nbsp;&nbsp; string[] strFiles = Directory.GetFiles(strFromPath);<\/p>\n<p>&nbsp;&nbsp; \/\/\u5faa\u73af\u62f7\u8d1d\u6587\u4ef6<br \/>&nbsp;&nbsp; for(int i = 0;i &lt; strFiles.Length;i++)<br \/>&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp; \/\/\u53d6\u5f97\u62f7\u8d1d\u7684\u6587\u4ef6\u540d\uff0c\u53ea\u53d6\u6587\u4ef6\u540d\uff0c\u5730\u5740\u622a\u6389\u3002<br \/>&nbsp;&nbsp;&nbsp; string strFileName = strFiles[i].Substring(strFiles[i].LastIndexOf(&#8220;\\\\&#8221;) + 1,strFiles[i].Length &#8211; strFiles[i].LastIndexOf(&#8220;\\\\&#8221;) &#8211; 1);<br \/>&nbsp;&nbsp;&nbsp; \/\/\u5f00\u59cb\u62f7\u8d1d\u6587\u4ef6,true\u8868\u793a\u8986\u76d6\u540c\u540d\u6587\u4ef6<br \/>&nbsp;&nbsp;&nbsp; File.Copy(strFiles[i],strToPath + &#8220;\\\\&#8221; + strFolderName + &#8220;\\\\&#8221; + strFileName,true);<br \/>&nbsp;&nbsp; }<\/p>\n<p>&nbsp;&nbsp; \/\/\u521b\u5efaDirectoryInfo\u5b9e\u4f8b<br \/>&nbsp;&nbsp; DirectoryInfo dirInfo = new DirectoryInfo(strFromPath);<br \/>&nbsp;&nbsp; \/\/\u53d6\u5f97\u6e90\u6587\u4ef6\u5939\u4e0b\u7684\u6240\u6709\u5b50\u6587\u4ef6\u5939\u540d\u79f0<br \/>&nbsp;&nbsp; DirectoryInfo[] ZiPath = dirInfo.GetDirectories();<br \/>&nbsp;&nbsp; for (int j = 0;j &lt; ZiPath.Length;j++)<br \/>&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp; \/\/\u83b7\u53d6\u6240\u6709\u5b50\u6587\u4ef6\u5939\u540d<br \/>&nbsp;&nbsp;&nbsp; string strZiPath = strFromPath + &#8220;\\\\&#8221; + ZiPath[j].ToString();&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp; \/\/\u628a\u5f97\u5230\u7684\u5b50\u6587\u4ef6\u5939\u5f53\u6210\u65b0\u7684\u6e90\u6587\u4ef6\u5939\uff0c\u4ece\u5934\u5f00\u59cb\u65b0\u4e00\u8f6e\u7684\u62f7\u8d1d<br \/>&nbsp;&nbsp;&nbsp; CopyFolder(strZiPath,strToPath + &#8220;\\\\&#8221; + strFolderName);<br \/>&nbsp;&nbsp; }<br \/>}<\/p>\n<p>\u4e00\uff0e\u8bfb\u53d6\u6587\u672c\u6587\u4ef6<br \/>1\/**\/\/\/\/ &lt;summary&gt;<br \/>2\/\/\/ \u8bfb\u53d6\u6587\u672c\u6587\u4ef6<br \/>3\/\/\/ &lt;\/summary&gt;<br \/>4private void ReadFromTxtFile()<br \/>5{<br \/>6&nbsp;&nbsp;&nbsp; if(filePath.PostedFile.FileName != &#8220;&#8221;)<br \/>7&nbsp;&nbsp;&nbsp; {<br \/>8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txtFilePath =filePath.PostedFile.FileName;<br \/>9&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fileExtName = txtFilePath.Substring(txtFilePath.LastIndexOf(&#8220;.&#8221;)+1,3);<br \/>10<br \/>11&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(fileExtName !=&#8221;txt&#8221; &amp;&amp; fileExtName != &#8220;TXT&#8221;)<br \/>12&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>13&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Write(&#8220;\u8bf7\u9009\u62e9\u6587\u672c\u6587\u4ef6&#8221;);<br \/>14&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>15&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br \/>16&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>17&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; StreamReader fileStream = new StreamReader(txtFilePath,Encoding.Default);<br \/>18&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txtContent.Text = fileStream.ReadToEnd();<br \/>19&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fileStream.Close();<br \/>20&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>21&nbsp;&nbsp;&nbsp; }<br \/>22 }<\/p>\n","protected":false},"excerpt":{"rendered":"<p>C#\u8ffd\u52a0\u6587\u4ef6 StreamWriter sw = File.AppendText(Server.MapPath [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,8],"tags":[],"class_list":["post-605","post","type-post","status-publish","format-standard","hentry","category-1","category-oldblog"],"views":245,"_links":{"self":[{"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/posts\/605","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=605"}],"version-history":[{"count":1,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/posts\/605\/revisions"}],"predecessor-version":[{"id":786,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/posts\/605\/revisions\/786"}],"wp:attachment":[{"href":"http:\/\/www.ntxz.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=605"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=605"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}