• .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);
  • 相关阅读:
    Pro/Toolkit示例之一:异步启动ProE
    Formatted MessageBox/AfxMessageBox
    Pro/Toolkit示例之二:同步Dll程式
    模拟按钮控件BN_CLICKED消息事件
    详解ProToolkit注册文件
    C++函数指针
    Message Basic
    C++指针之间的赋值与转换规则总结
    CString&CStringA&CStringW之间的相互转换
    Devexpress组件之XtraBars.PopupMenu的使用
  • 原文地址:https://www.cnblogs.com/yuanws/p/968643.html
Copyright © 2020-2023  润新知