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

熱點內容
無憂傳奇版本 瀏覽:323
監測時事app哪個好 瀏覽:143
文件名提取第一位數字 瀏覽:70
魅族基帶怎麼升級 瀏覽:884
印度投資app有哪些 瀏覽:362
電腦怎麼將文件夾轉化為pdf格式 瀏覽:899
批量修改配置文件 瀏覽:320
安卓qq破解無升級版 瀏覽:96
編程從哪裡開始比較好 瀏覽:603
如何提取excel的文字快速建文件夾 瀏覽:884
沙畫教程下載 瀏覽:442
沒有顯示器自定義的icc配置文件 瀏覽:937
蘋果手錶2價格 瀏覽:516
word中口小框框變黑色 瀏覽:209
新網站被k關鍵詞堆砌怎麼修改 瀏覽:377
車載u盤文件夾歌曲如何選擇 瀏覽:58
網通網路提速 瀏覽:946
聖安地列斯為什麼要數據包 瀏覽:181
刪除一個文件用什麼編程軟體好 瀏覽:114
51單片機多少根數據線 瀏覽:731

友情鏈接