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

熱點內容
cudp文件傳輸 瀏覽:452
mac文件保存找不到桌面 瀏覽:614
數控編程軟體使用最多是哪個 瀏覽:324
root版本 瀏覽:61
html表格顏色代碼 瀏覽:805
java雙目運算符 瀏覽:159
qq古代唯美女生頭像 瀏覽:893
app資料庫伺服器配置 瀏覽:938
如何在電視上安裝米家app 瀏覽:991
二手物品哪個網站好 瀏覽:943
jdk轉換時找不到文件 瀏覽:345
在電腦上怎樣刪除文件夾 瀏覽:708
魅族手機黑屏找不到文件 瀏覽:729
如何找回qq幾年前的數據 瀏覽:867
不想學編程選什麼專業 瀏覽:97
華為g610一t11大聲音rom版本下載 瀏覽:645
背景音樂通常採用wav格式的音樂文件 瀏覽:218
java程序員提高班 瀏覽:67
為什麼要發明可編程式控制制器 瀏覽:846
電腦顯示佔用空間找不到文件 瀏覽:963

友情鏈接