.net 文件操作的一点记录
2007-11-22 15:07
477 查看
1.
string cnnstring = System.Configuration.ConfigurationSettings.AppSettings["Oracle"].ToString();
OracleConnection conn=new OracleConnection(cnnstring);
OracleCommand cmd=new OracleCommand("select spxxid,spdt from jt_j_spxx where spdt is not null order by spxxid desc ",conn);
//OracleCommand cmd=new OracleCommand("select spxxid,spdt from jt_j_spxx order by spxxid desc ",conn);
//OracleCommand cmd=new OracleCommand("select spxxid,spdt from jt_j_spxx where spxxid='756336553'",conn);
conn.Open();
OracleDataReader myReader;
myReader = cmd.ExecuteReader();
while(myReader.Read())
{
fpath = Server.MapPath(Request.ApplicationPath)+"/image/"+myReader.GetString(0)+".jpg";
fs =new FileStream(fpath, FileMode.OpenOrCreate, FileAccess.Write);
bw = new BinaryWriter(fs);
outbyte = (byte[])myReader[1];
bw.Write(outbyte);
bw.Flush();
bw.Close();
fs.Close();
}
myReader.Close();
conn.Close();
2.
upfile(System.Configuration.ConfigurationSettings.AppSettings["ForumUrl"]+"/Movie/default.aspx","~/Movie/index.html");
public void upfile(string url,string mappath)
{
try
{
Uri UrlPage= new Uri(url);
HttpWebRequest hwReq = (HttpWebRequest)WebRequest.Create(UrlPage);
hwReq.Timeout = 50000 ;
HttpWebResponse hwRes = (HttpWebResponse)hwReq.GetResponse();
hwReq.Method = "Post";
hwReq.KeepAlive = true;
StreamWriter fs =new StreamWriter(Server.MapPath(mappath),false,System.Text.Encoding.UTF8);
StreamReader fs2=new StreamReader(hwRes.GetResponseStream(),System.Text.Encoding.UTF8);
string nextline;
while((nextline=fs2.ReadLine())!=null)
{
fs.WriteLine(nextline);
}
fs.Close();
fs2.Close();
Response.Write("<script>alert('生成成功');</script>");
}
catch
{
Response.Write("<script>alert('生成超时,请重新生成');</script>");
}
}
3.
if(File.Exists(Server.MapPath("../zthtml/temp/"+str))==false)
{
Response.Write("<script>alert('没有找到模板,请确定模板的名字正确!');</script>");
}
else
{
StreamReader objReader = new StreamReader(Server.MapPath("~/zthtml/temp/"+str),System.Text.Encoding.GetEncoding("gb2312"));
string sLine="";
sLine=objReader.ReadToEnd();
objReader.Close();
}StreamWriter sw=new StreamWriter(Server.MapPath("~/zthtml/"+str.Substring(0,str.IndexOf(".",1))+".shtml"),false,System.Text.Encoding.GetEncoding("gb2312"),sLine.Length);
sw.Write(sLine);
string cnnstring = System.Configuration.ConfigurationSettings.AppSettings["Oracle"].ToString();
OracleConnection conn=new OracleConnection(cnnstring);
OracleCommand cmd=new OracleCommand("select spxxid,spdt from jt_j_spxx where spdt is not null order by spxxid desc ",conn);
//OracleCommand cmd=new OracleCommand("select spxxid,spdt from jt_j_spxx order by spxxid desc ",conn);
//OracleCommand cmd=new OracleCommand("select spxxid,spdt from jt_j_spxx where spxxid='756336553'",conn);
conn.Open();
OracleDataReader myReader;
myReader = cmd.ExecuteReader();
while(myReader.Read())
{
fpath = Server.MapPath(Request.ApplicationPath)+"/image/"+myReader.GetString(0)+".jpg";
fs =new FileStream(fpath, FileMode.OpenOrCreate, FileAccess.Write);
bw = new BinaryWriter(fs);
outbyte = (byte[])myReader[1];
bw.Write(outbyte);
bw.Flush();
bw.Close();
fs.Close();
}
myReader.Close();
conn.Close();
2.
upfile(System.Configuration.ConfigurationSettings.AppSettings["ForumUrl"]+"/Movie/default.aspx","~/Movie/index.html");
public void upfile(string url,string mappath)
{
try
{
Uri UrlPage= new Uri(url);
HttpWebRequest hwReq = (HttpWebRequest)WebRequest.Create(UrlPage);
hwReq.Timeout = 50000 ;
HttpWebResponse hwRes = (HttpWebResponse)hwReq.GetResponse();
hwReq.Method = "Post";
hwReq.KeepAlive = true;
StreamWriter fs =new StreamWriter(Server.MapPath(mappath),false,System.Text.Encoding.UTF8);
StreamReader fs2=new StreamReader(hwRes.GetResponseStream(),System.Text.Encoding.UTF8);
string nextline;
while((nextline=fs2.ReadLine())!=null)
{
fs.WriteLine(nextline);
}
fs.Close();
fs2.Close();
Response.Write("<script>alert('生成成功');</script>");
}
catch
{
Response.Write("<script>alert('生成超时,请重新生成');</script>");
}
}
3.
if(File.Exists(Server.MapPath("../zthtml/temp/"+str))==false)
{
Response.Write("<script>alert('没有找到模板,请确定模板的名字正确!');</script>");
}
else
{
StreamReader objReader = new StreamReader(Server.MapPath("~/zthtml/temp/"+str),System.Text.Encoding.GetEncoding("gb2312"));
string sLine="";
sLine=objReader.ReadToEnd();
objReader.Close();
}StreamWriter sw=new StreamWriter(Server.MapPath("~/zthtml/"+str.Substring(0,str.IndexOf(".",1))+".shtml"),false,System.Text.Encoding.GetEncoding("gb2312"),sLine.Length);
sw.Write(sLine);
相关文章推荐
- Linux文件操作_日常记录
- 对文件存贮结构体变量的一些操作记录及几个错误解决
- .net对xml文件操作总结
- 使用FileReference+HttpHandler实现文件上传/下载(Flex与.NET互操作)
- Linux 入门记录:三、Linux 文件基本操作管理
- 【转载】返璞归真 asp.net mvc (11) - asp.net mvc 4.0 新特性之自宿主 Web API, 在 WebForm 中提供 Web API, 通过 Web API 上传文件, .net 4.5 带来的更方便的异步操作
- Ibator生成iBATIS配置文件、DO及DAO操作记录
- Flex与.NET互操作(五):使用FileReference+HttpHandler实现文件上传/下载
- 返璞归真 asp.net mvc (11) - asp.net mvc 4.0 新特性之自宿主 Web API, 在 WebForm 中提供 Web API, 通过 Web API 上传文件, .net 4.5 带来的更方便的异步操作
- 在.NET平台用DocX操作Word文件
- .Net编程对文件系统操作示例(转)
- 黑马程序员_Java基础_IO流_字节流,字节流操作文件,缓冲区字节流,流的使用规律,异常记录原理
- 数据库用裸设备做数据文件的一点记录
- Linux下oracle11gR2系统安装到数据库建立配置及最后oracle的dmp文件导入一站式操作记录
- C#记录日志,文件操作
- 关于Python操作txt文件的一点尝试
- 整合springboot+mvc+mybatis(通用mapper)+druid+jsp+bootstrap实现权限管理文件上传下载多数据源切换操作日志记录等功能
- CAB文件制作方法,OCX、DLL打包为CAB操作记录
- 如何记录文件服务器上的文件操作日志
- 学习记录-Qt文件的读写和删除等操作