• .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);
  • 相关阅读:
    okhttp进行网络传输文件
    bazel、tensorflow_serving、opencv编译问题
    Linux下设置和查看环境变量(转)
    std::move的实际工作过程
    虚拷贝
    移动构造函数和移动赋值
    while(cin>>word)时的结束方法
    转:windows下命令行工具
    eclipse大括号高亮显示---颜色很淡,改为显眼的颜色
    转: Eclipse 分屏显示同一个文件
  • 原文地址:https://www.cnblogs.com/yuanws/p/968643.html
Copyright © 2020-2023  润新知