C# asp.net页面接收的数据保存到Txt文件中, C#将数据保存到记录本中 conquer
2010-01-12 16:07
615 查看
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
namespace URLSendValTest
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string strDisp = Request.QueryString["SendVal"].ToString();
//string strDisp = "中华人民共和国";
TextBox1.Text=strDisp;
// 将数据保存到Txt文件中
CreateTxt(strDisp);
}
public void CreateTxt(string strDisp)
{
/** //********页面报权限不够的错*****************
*在D盘建立 aa.txt文件
*
* * 在写入数据时需给被写入的文件加入 写入权限和 asp.net帐户,NETWORK SERVICE帐户
* 属 性-->>安全-->>添加-->>查找位置改为本机-->>高级-->>立即查找 -->>[选择所要的]
* */
string filename = "aa";
FileStream fs = new FileStream(@"d:\" + filename + ".txt",FileMode.Open, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("GB2312"));//通过指定字符编码方式可以实现对汉字的支持,否则在用记 事本打开查看会出现乱码
sw.Flush();
sw.BaseStream.Seek(0, SeekOrigin.End); //从哪里开始写入.
sw.WriteLine(strDisp);
sw.Flush();
sw.Close();
Page.ClientScript.RegisterStartupScript(this.GetType(), @"alert('成功!');", "scriptName");
//using (StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("GB2312")))
//{
// // Add some text to the file.
// sw.Write("This is the ");
// sw.WriteLine("header for the file.");
// sw.WriteLine("-------------------");
// // Arbitrary objects can also be written to the file.
// sw.Write("The date is: ");
// sw.WriteLine(DateTime.Now);
//}
//Page.ClientScript.RegisterStartupScript(this.GetType(), @"alert('成功!');", "scriptName");
}
protected void Button1_Click(object sender, EventArgs e)
{
}
}
}
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
namespace URLSendValTest
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string strDisp = Request.QueryString["SendVal"].ToString();
//string strDisp = "中华人民共和国";
TextBox1.Text=strDisp;
// 将数据保存到Txt文件中
CreateTxt(strDisp);
}
public void CreateTxt(string strDisp)
{
/** //********页面报权限不够的错*****************
*在D盘建立 aa.txt文件
*
* * 在写入数据时需给被写入的文件加入 写入权限和 asp.net帐户,NETWORK SERVICE帐户
* 属 性-->>安全-->>添加-->>查找位置改为本机-->>高级-->>立即查找 -->>[选择所要的]
* */
string filename = "aa";
FileStream fs = new FileStream(@"d:\" + filename + ".txt",FileMode.Open, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("GB2312"));//通过指定字符编码方式可以实现对汉字的支持,否则在用记 事本打开查看会出现乱码
sw.Flush();
sw.BaseStream.Seek(0, SeekOrigin.End); //从哪里开始写入.
sw.WriteLine(strDisp);
sw.Flush();
sw.Close();
Page.ClientScript.RegisterStartupScript(this.GetType(), @"alert('成功!');", "scriptName");
//using (StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("GB2312")))
//{
// // Add some text to the file.
// sw.Write("This is the ");
// sw.WriteLine("header for the file.");
// sw.WriteLine("-------------------");
// // Arbitrary objects can also be written to the file.
// sw.Write("The date is: ");
// sw.WriteLine(DateTime.Now);
//}
//Page.ClientScript.RegisterStartupScript(this.GetType(), @"alert('成功!');", "scriptName");
}
protected void Button1_Click(object sender, EventArgs e)
{
}
}
}
相关文章推荐
- C# asp.net页面接收的数据保存到Txt文件中, C#将数据保存到记录本中 conquer
- C#(asp.net)保存数据到文件,读取文件数据
- asp.net(c#)如何读取上传过程中的.txt文件中的数据,并将其写入数据库的
- [网络收集]asp.net(c#) 保存xml数据(将数据写入到xml文件中)
- asp.net 文件上传与刷新与asp.net页面与iframe之间的数据传输
- 【转载】Asp.NET大文件上传组件开发总结(四)---封送数据给Asp.NET页面
- asp.net实现从Txt文件读取数据到数据视图的方法
- asp.net从数据库导出数据到word、excel、txt文本文件
- Asp.Net 上传大文件专题(3)--从请求流中获取数据并保存为文件[下]
- 【asp.net小札记】页面后台Post数据并接收返回数据
- UpdatePanel 和 Repeater实现页面局部数据无刷新 (asp.net C#)
- 【转】Asp.NET大文件上传组件开发总结(四)---封送数据给Asp.NET页面
- [ASP.NET]如何点击按钮弹出新窗口,输入数据后返回并刷新页面?(C#代码)
- ASP.NET(用c#),弹出文件保存对话框窗口
- Asp.Net 上传大文件专题(3)--从请求流中获取数据并保存为文件[上]
- asp.net 文件上传与刷新与asp.net页面与iframe之间的数据传输
- Asp.Net 上传大文件专题(3)--从请求流中获取数据并保存为文件[上]
- C#编译器优化那点事 c# 如果一个对象的值为null,那么它调用扩展方法时为甚么不报错 webAPI 控制器(Controller)太多怎么办? .NET MVC项目设置包含Areas中的页面为默认启动页 (五)Net Core使用静态文件 学习ASP.NET Core Razor 编程系列八——并发处理
- Asp.Net 上传大文件专题(3)--从请求流中获取数据并保存为文件[下]
- 在asp.net中如何用LinkBtutton按钮实现安全退出,并保存当前页面数据与数据库中