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

熱點內容
怎麼判斷路徑是文件夾 瀏覽:611
測量員輸入平曲線數據有哪些應用 瀏覽:14
微信10元紅包尾數概率 瀏覽:922
網頁背景圖片代碼 瀏覽:391
pkpm能轉低版本 瀏覽:725
c程序設計課件 瀏覽:327
qq炫舞客戶端怎麼修復工具 瀏覽:537
結算需要cad源文件嗎 瀏覽:446
編程在哪裡簽到 瀏覽:472
什麼網站能看美女直播 瀏覽:148
linux生成excel格式的文件 瀏覽:230
win10開key文件 瀏覽:527
如何看待網路流行用語作文 瀏覽:296
xpsp1升級到sp3打補丁360 瀏覽:389
r語言怎麼讀取txt數據 瀏覽:114
壓縮文件管用嗎 瀏覽:410
華為官網app圖標是哪個 瀏覽:603
中標麒麟共享主機的文件路徑 瀏覽:309
滴答出行app怎麼下載 瀏覽:990
蘋果5怎麼屏幕變色了 瀏覽:753

友情鏈接