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

熱點內容
115網盤解析工具2014 瀏覽:371
內圓弧銑刀怎麼編程 瀏覽:410
記事本文件轉word格式對齊 瀏覽:300
excel刪除恢復文件 瀏覽:290
三星s4怎麼切換3g網路 瀏覽:994
什麼是網站維護 瀏覽:314
文件夾錄像在哪裡 瀏覽:621
可以發語音的是什麼app 瀏覽:804
恢復手機桌面文件管理 瀏覽:627
用什麼軟體可以打開psd文件 瀏覽:459
公安有哪些警務app 瀏覽:150
生意轉租用什麼app 瀏覽:683
廣義的網路信息保密性是指 瀏覽:657
qq背景唯美簡約圖片 瀏覽:292
sky網路電話怎麼收費 瀏覽:599
編程公司哪個比較好 瀏覽:182
修改歸檔日誌文件的路徑 瀏覽:8
配置文件替換 瀏覽:117
mac右鍵沒有刪除文件 瀏覽:624
蘋果手機游戲文稿和數據在哪清理 瀏覽:326

友情鏈接