zoukankan      html  css  js  c++  java
  • .net 文件操作的一点记录

    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);
  • 相关阅读:
    Knol of Fabio Maulo
    调用非.net系统的Webservice的探索 ( 二 ) WSE
    在Sql Server 使用系统存储过程sp_rename修改表名或列名
    Who is locking the DB account?
    (python learn) 7 字典
    (python learn) 8 流程控制
    (python learn) 4 number&& string
    where is the data come from after we drop the table
    (healthy recorder) 治疗第6天
    (python learn) 6 列表
  • 原文地址:https://www.cnblogs.com/yuanws/p/968643.html
Copyright © 2011-2022 走看看