ASP.NET在本地服务器上创建目录并在该目录下写文件
public static Boolean WriteTextFile(string content, string filepath,string name)
{
FileStream fs;
StreamWriter sw;
if (!System.IO.Directory.Exists(filepath))
{
DirectoryInfo DirInfo = Directory.CreateDirectory(filepath); //创建目录
DirInfo.Attributes = FileAttributes.Normal;
}
string fullpath = filepath + name + ".txt";
if (File.Exists(fullpath))//验证文件是否存在
{
return false;
}
else
{
fs = new FileStream(fullpath, FileMode.Create, FileAccess.Write);
sw = new StreamWriter(fs,System.Text.Encoding.Default);
sw.WriteLine(content);
sw.Close();
fs.Close();
return true;
}
}
在做这个相关工作的时候 还碰到一个问题就是 用一下方法读取中文文本文件时,出现乱码的现象:
public static String ReadTextFile(string filepath)
{
StreamReader objReader = new StreamReader(filepath);
string sLine = "";
ArrayList arrText = new ArrayList();
while (sLine != null)
{
sLine = objReader.ReadLine();
if (sLine != null)
arrText.Add(sLine);
}
objReader.Close();
StringBuilder sb = new StringBuilder();
foreach (string sOutput in arrText)
sb.Append(sOutput);
return sb.ToString();
}
查询资料 发现对上面代码中的StreamReader修改一下,如下代码:
public static String ReadTextFile(string filepath)
{
StreamReader objReader = new StreamReader(filepath, System.Text.Encoding.Default);
string sLine = "";
ArrayList arrText = new ArrayList();
while (sLine != null)
{
sLine = objReader.ReadLine();
if (sLine != null)
arrText.Add(sLine);
}
objReader.Close();
S
相关文档:
第一:
Response.Write(<script></script>);
第二:
托一个Literal控件
Literal(控件名).Text="<script></script>";
......
最近公司有一个小项目需要把视频转换成FLASH文件,效果就是像用户注册youku网一样,自己可以视频上传,转换成flash格式播放。
苦于以前没有做过,于是马上搜索了相关的文章,看了http://www.cnblogs.com/xiucai/ 和 http://www.cnblogs.com/seebook/关于这方面的文章,对我帮助很大。今天第一天开博,我就记录下它们。
现 ......
ASP.NET常见安全问题
一、SQL语句漏洞
许多程序员在用sql语句进行用户密码验证时是通过一个类似这样的语句来实现的:
Sql="Select * from 用户表 where 姓名 = '" + name + "' and 密码 = '" + password + "'"
通过分析可以发现,上述语句存在着致命的漏洞。当我们在用户名称中输入下面的字符串时:tes ......
一、目前在ASP.NET中页面传值共有这么几种方式:
第一种方法:
通过URL链接地址传递
send.aspx:
protected void Button1_Click(object sender, EventArgs e)
{
Request.Redirect("Default2.aspx?usern ......
一说到新闻系统的话,一定会谈到静态页面生成的,因为静态页面不但是读取速度快,而且又安全;
静态页面的生成不管是小到现在的企业网站大至网易,QQ等门户都用到了;
那么我们如何来生成静态页呢?
以什么方式生成静态页面呢……
在生成静态页面的时候有那些是要注意的呢:
静态页面命名
统一存放目录 ......