您的位置:首页 > 其它

【项目实战】--Office文件导出

2015-05-31 22:10 344 查看
文件的下载:

try{   
    string savePath = ""//保存路劲      
    downFileUrl = "";//下载文件链接地址   
    WebClient wcClient = new WebClient();   
    WebRequest webReq = WebRequest.Create(downFileUrl);    
    WebResponse webRes = webReq.GetResponse();  
    int fileLength = webRes.ContentLength;  
    Stream srm = webRes.GetResponseStream();  
    StreamReader srmReader = new StreamReader(srm);   
    byte[] bufferbyte = new byte[fileLength];   
    int allByte = (int)bufferbyte.Length;  
    int startByte = 0;  
    while (fileLength > 0)    
    {   
        //Application.DoEvents();       
        int downByte = srm.Read(bufferbyte, startByte, allByte);      
        if (downByte == 0) { break; };      
        startByte += downByte;     
        allByte -= downByte;  
    }   
    if (!File.Exists(savePath))   
    {      
        string[] dirArray = savePath.Split('\\');     
        string temp = string.Empty;     
        for (int i = 0; i < dirArray.Length - 1; i++)        
        {         
            temp += dirArray[i].Trim() + "\\";      
            if (!Directory.Exists(temp))Directory.CreateDirectory(temp);   
        }  
    }  
    FileStream fs = new FileStream(savePath, FileMode.OpenOrCreate, FileAccess.Write);   
    fs.Write(bufferbyte, 0, bufferbyte.Length);   
    srm.Close(); 
    srmReader.Close();  
    fs.Close();
}
catch (WebException ex)
{  
    throw ex;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: