導航:首頁 > 版本升級 > net生成txt文件

net生成txt文件

發布時間:2024-12-04 06:43:51

Ⅰ 在asp.net中如何用文件流生成一個.txt文件,並保存在伺服器端

在按鈕事件里寫:
if(TextBox1.Text!=""&&TextBox1.Text!="")
{
string path = Server.MapPath("Files") + "\\" + TextBox1.Text.Trim();
//TextBox1.Text.Trim()這個控制項用來獲取文件名字和類型,比如1.text;Files文件是項目裡面的一個文件,新建的text文件放在此目錄下,可以自己根據自己的寫
FileInfo fi=new FileInfo(path);
if(!fi.Exists)
{
StreamWriter sw = fi.CreateText();
sw.WriteLine(TextBox2.Text.Trim());
//這是寫入文件的內容,不寫空就是了
sw.Flush();
sw.Close();
}
Label1.Text = "成功";
//指示是否成功
}
else
{
Label1.Text = "請輸入文件名和文件類型";
}

Ⅱ 在.net中如何生成一個txt文本文檔

public static void WriteToFile(string name, string content, bool isCover)
{
FileStream fs = null;
try
{
if (!isCover && File.Exists(name))
{
fs = new FileStream(name, FileMode.Append, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
sw.WriteLine(content);
sw.Flush();
sw.Close();
}
else
{
File.WriteAllText(name, content, Encoding.UTF8);
}
}
finally
{
if (fs != null)
{
fs.Close();
}
}

}

閱讀全文

與net生成txt文件相關的資料

熱點內容
6s用哪個版本好 瀏覽:324
數控編程怎麼來的 瀏覽:103
廣西廣電網路的默認ip 瀏覽:191
政府發紅頭文件內容會實現嗎 瀏覽:552
騰訊貴安七星數據中心英文怎麼寫 瀏覽:489
玩火的女孩有幾個版本 瀏覽:113
tvshowtracker安卓版 瀏覽:983
App數據分析應該從哪些緯度 瀏覽:17
到底要不要升級ios92 瀏覽:875
cad2014安裝包安裝文件在哪裡 瀏覽:63
電信密碼無法登錄 瀏覽:820
cad的列印到文件怎麼設置 瀏覽:902
智行app鉑金會員怎麼還有期限 瀏覽:581
win10用子文件夾改名 瀏覽:234
ae鋼筆工具在哪裡 瀏覽:460
gn105數據線插哪裡 瀏覽:916
破鎖屏密碼方法 瀏覽:835
股票數據放哪裡 瀏覽:576
m格式庫文件 瀏覽:279
天際通數據服務怎麼開票 瀏覽:430

友情鏈接