Response.ContentType = "application/msword";

解决方案 »

  1.   

    给你个文件下载的例子!
    using System;
    using System.IO;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Net; 
    using System.Threading;namespace Sx_Mdi
    { /// <summary>
    /// Summary description for Class1.
    /// </summary>
    public class CIniFile
    {
    //文件INI名称
    public string Path;
    ////声明读写INI文件的API函数 
    [DllImport("kernel32")]
    private static extern long WritePrivateProfileString(string section,string key,string val,string filePath);
    [DllImport("kernel32")] private static extern int GetPrivateProfileString(string section,string key,string def,StringBuilder retVal,int size,string filePath); //类的构造函数,传递INI文件名
    public CIniFile(string inipath)
    {
    //
    // TODO: Add constructor logic here
    //
    Path = inipath;
    } //写INI文件
    public void IniWriteValue(string Section,string Key,string Value)
    {
    WritePrivateProfileString(Section,Key,Value,this.Path);
    } //读取INI文件指定
    public string IniReadValue(string Section,string Key)
    {
    StringBuilder temp = new StringBuilder(255);
    int i = GetPrivateProfileString(Section,Key,"",temp,255,this.Path);
    return temp.ToString();
    }
    }
    public class CDownLoadFile
    {
    public string strSrcPath;
    public string strTargetPath;
    private WebClient client = new WebClient(); 
    public CDownLoadFile()
    {
    strSrcPath = "";
    strTargetPath = "";
    }
    public CDownLoadFile(string strSrc,string strTarget)
    {
    strSrcPath = strSrc;
    strTargetPath = strTarget;
    }
    public string StartDownload() 

    string URL = strSrcPath; 
    int n = URL.LastIndexOf('/'); 
    string URLAddress = URL;//.Substring(0,n); 
    string fileName = URL.Substring(n+1,URL.Length-n-1); 
    string Dir = strTargetPath; 
    string Path = Dir+'\\'+fileName;  try 

    WebRequest myre=WebRequest.Create(URLAddress); 

    catch(WebException exp) 

    return exp.Message; 
    }  try 

    //"开始下载文件..."; 
    client.DownloadFile(URLAddress,fileName); 
    Stream str = client.OpenRead(URLAddress); 
    StreamReader reader = new StreamReader(str); 
    byte[] mbyte = new byte[1000000]; 
    int allmybyte = (int)mbyte.Length; 
    int startmbyte = 0; 
    //"正在接收数据..."; 
    while(allmybyte>0) 

    int m = str.Read(mbyte,startmbyte,allmybyte); 
    if(m==0) 
    break;  startmbyte+=m; 
    allmybyte-=m; 
    }  FileStream fstr = new FileStream(Path,FileMode.OpenOrCreate ,FileAccess.Write); 
    fstr.Write(mbyte,0,startmbyte); 
    str.Close(); 
    fstr.Close(); 

    catch(WebException exp) 

    return exp.Message;  
    // ""; 
    }  return "";  
    } }}
      

  2.   

    请问?
    byte[] file = (byte[])dbValue中,dbValue如何定义?
    Response.BinaryWrite(file)作用是什么?