Asp.NET(asp)写文件的一个小实例程序。
2008-10-23 09:55
260 查看
Asp.NET写文件的一个小实例程序。
#region 写文件
/****************************************
* 函数名称:WriteFile
* 功能说明:当文件不存时,则创建文件,并追加文件
* 参 数:Path:文件路径,Strings:文本内容
* 调用示列:
* string Path = Server.MapPath("Default2.aspx");
* string Strings = "这是我写的内容啊";
* EC.FileObj.WriteFile(Path,Strings);
*****************************************/
///
/// 写文件
///
/// 文件路径
/// 文件内容
public static void WriteFile(string Path, string Strings)
{
if (!System.IO.File.Exists(Path))
{
System.IO.FileStream f = System.IO.File.Create(Path);
f.Close();
}
System.IO.StreamWriter f2 = new System.IO.StreamWriter(Path, true, System.Text.Encoding.GetEncoding("gb2312"));
f2.WriteLine(Strings);
f2.Close();
f2.Dispose();
}
#endregion
下面是asp的写文件的一个小实例程序。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<%
cip=Request.ServerVariables("REMOTE_ADDR")
%>
<body>
cip=<%=cip%>
<%
Dim fso, f1, ts, s,strsql,strcityid,strfile
strcityid=request.QueryString("CityID")
strfile="../IPTXT/"&strcityid&".txt"
Const ForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.CreateTextFile(server.mappath("../IPTXT/"+strcityid+".txt"), True)
' 写一行。server.mappath("data/bfxx.mdb"
'Response.Write "Writing file <br>"
f1.WriteLine cip
f1.WriteBlankLines(1)
f1.Close
' 读取文件的内容。
'Response.Write "Reading file <br>"
Set ts = fso.OpenTextFile(server.mappath("../IPTXT/"+strcityid+".txt"), ForReading)
s = ts.ReadLine
'Response.Write "File contents = '" & s & "'"
ts.Close
%>
</body>
</html>
#region 写文件
/****************************************
* 函数名称:WriteFile
* 功能说明:当文件不存时,则创建文件,并追加文件
* 参 数:Path:文件路径,Strings:文本内容
* 调用示列:
* string Path = Server.MapPath("Default2.aspx");
* string Strings = "这是我写的内容啊";
* EC.FileObj.WriteFile(Path,Strings);
*****************************************/
///
/// 写文件
///
/// 文件路径
/// 文件内容
public static void WriteFile(string Path, string Strings)
{
if (!System.IO.File.Exists(Path))
{
System.IO.FileStream f = System.IO.File.Create(Path);
f.Close();
}
System.IO.StreamWriter f2 = new System.IO.StreamWriter(Path, true, System.Text.Encoding.GetEncoding("gb2312"));
f2.WriteLine(Strings);
f2.Close();
f2.Dispose();
}
#endregion
下面是asp的写文件的一个小实例程序。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<%
cip=Request.ServerVariables("REMOTE_ADDR")
%>
<body>
cip=<%=cip%>
<%
Dim fso, f1, ts, s,strsql,strcityid,strfile
strcityid=request.QueryString("CityID")
strfile="../IPTXT/"&strcityid&".txt"
Const ForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.CreateTextFile(server.mappath("../IPTXT/"+strcityid+".txt"), True)
' 写一行。server.mappath("data/bfxx.mdb"
'Response.Write "Writing file <br>"
f1.WriteLine cip
f1.WriteBlankLines(1)
f1.Close
' 读取文件的内容。
'Response.Write "Reading file <br>"
Set ts = fso.OpenTextFile(server.mappath("../IPTXT/"+strcityid+".txt"), ForReading)
s = ts.ReadLine
'Response.Write "File contents = '" & s & "'"
ts.Close
%>
</body>
</html>
相关文章推荐
- Asp.NET写文件的一个小实例程序
- ASP.NET中实现多文件上传的实例程序代码
- asp.net 未能加载文件或程序集“XXX”或它的某一个依赖项。试图加载格式不正确的程序。
- [导入]开源一个的Asp.net公共上传文件程序
- 分享一个管理硬盘中的音乐文件的ASP.NET程序,仅限于我个人的处理方式
- [导入]开源一个的Asp.net公共上传文件程序
- ASP.NET程序上传文件功能的具体实例代码
- asp.net 未能加载文件或程序集“XXX”或它的某一个依赖项。试图加载格式不正确的程序。
- c# asp.net web程序获取当前文件路径
- asp.net网站未能加载文件或程序集或它的某一个依赖项。拒绝访问
- asp.net多文件上传实例讲解
- asp.net多文件上传实例讲解
- asp.net输出重写压缩页面文件实例代码
- 自己写的一个资料验证的asp.net程序,大家看看吧!
- asp.net输出重写压缩页面文件实例
- ASP.NET中上传EXCEL文件一个比较快的方法
- sql server 关于表中只增标识问题 C# 实现自动化打开和关闭可执行文件(或 关闭停止与系统交互的可执行文件) ajaxfileupload插件上传图片功能,用MVC和aspx做后台各写了一个案例 将小写阿拉伯数字转换成大写的汉字, C# WinForm 中英文实现, 国际化实现的简单方法 ASP.NET Core 2 学习笔记(六)ASP.NET Core 2 学习笔记(三)
- Asp.Net操作MSSQL数据库的类-从增删改查讲起-附带一个小程序测试
- asp.net C#实现下载文件的六种方法实例
- IIS asp.net 中出现未能加载文件或程序集“System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”或它的某一个依赖项。系统找不到指定的文件。