導航:首頁 > 版本升級 > 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文件相關的資料

熱點內容
微信奢侈品法律風險 瀏覽:982
iejs實現全屏顯示 瀏覽:495
dnf90版本男格鬥武器 瀏覽:743
台灣網路電視台直播 瀏覽:332
文件夾主名 瀏覽:754
如何可以破譯wifi密碼嗎 瀏覽:213
hog特徵提取代碼c 瀏覽:447
網站定製和模板有什麼不同 瀏覽:529
蘋果耳機是幾單元 瀏覽:807
oppo手機藍牙怎麼傳文件 瀏覽:661
iphone同步文件夾 瀏覽:656
u盤存文件慢是什麼原因 瀏覽:608
iphone手機定位軟體破解版 瀏覽:34
win7取消共享文件密碼 瀏覽:519
怎麼練c編程 瀏覽:101
xml文件中的注釋是 瀏覽:353
報考質量內審員在什麼網站 瀏覽:883
服務網路拓撲怎麼變化 瀏覽:871
微信接收文件在電腦哪 瀏覽:232
java定時器定時執行一次 瀏覽:821

友情鏈接