Ⅰ .net如何下载文件
.net文件下载方式有好多种,你可以直接用链接定位到文件进行下载。 或者使用分流下载 string fileName = "aaa.txt";//客户端保存的文件名 string filePath = Server.MapPath("DownLoad/aaa.txt");//路径 //以字符流的形式下载文件 FileStream fs = new FileStream(filePath, FileMode.Open); byte[] bytes = new byte[(int)fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Close(); Response.ContentType = "application/octet-stream"; //通知浏览器下载文件而不是打开 Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); Response.BinaryWrite(bytes); Response.Flush(); Response.End(); 也可以使用分块进行下载。方式很多的 追问: 这个就是我想要!!!谢谢你了
Ⅱ 【vb.net】怎么把text里面的内容生成一个txt文件
()
'创建一个保存对话框
SaveFileDialog1.Filter="txtfiles(*.txt)|*.txt"
'设置扩展名
IfSaveFileDialog1.ShowDialog()=System.Windows.Forms.DialogResult.OKThen
'如果确定保存
My.Computer.FileSystem.WriteAllText(SaveFileDialog1.Filename,Textbox1.Text,False)
'保存文本,False表示不追加文本,直接覆盖其内容
EndIf
Ⅲ 在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();
}
}
}