C/S方式下怎么将WORD上传到SQL,并能实现下载。

解决方案 »

  1.   

    上传
    把文件读成二进制.
    转化为BASE64编码.保存到SQL数据库中...下载
    把数据库记录读出.
    DEBASE64后.转化为二进制写文件...
      

  2.   

    上传下载的方式,挺多
    有使用ftp的,还有使用socket(似乎看到socket也用在了ftp传输里面)
    你看看这个
    http://www.cnblogs.com/lovecherry/archive/2007/08/06/278459.html
      

  3.   

    直接保存到NTEXT的数据库字段中就行了
      

  4.   

    http://support.microsoft.com/kb/309158/zh-cn
      

  5.   

    public class FtpClass
        {
            private string FtpIP=ConfigurationSettings.AppSettings["FtpIP"];
            private string FtpUserName=ConfigurationSettings.AppSettings["FtpUserName"];
            private string FtpPassord=ConfigurationSettings.AppSettings["FtpPassWord"];
            private FtpConnection ftp;        private FtpConnection FtpConn()
            {
                ftp=new FtpConnection();
                ftp.Connect(this.FtpIP,this.FtpUserName,this.FtpPassord);
                return ftp;
            }        private string GetFileExtName(string filename,bool withdot)
            {
                string [] arrs=filename.Split('.');
                int i=arrs.Length;
                return withdot?"."+arrs[i-1].ToString():arrs[i-1].ToString();
            }        private string GetFileContentType(string filedownloadname)
            {
                string DEFAULT_CONTENT_TYPE = "application/unknown";
                RegistryKey regkey,fileextkey;
                string FileContentType;
                try 
                {                
                    regkey=Registry.ClassesRoot;                
                    fileextkey=regkey.OpenSubKey(this.GetFileExtName(filedownloadname,false));                
                    FileContentType=fileextkey.GetValue("Content Type",DEFAULT_CONTENT_TYPE).ToString();
                }
                catch
                {
                    FileContentType=DEFAULT_CONTENT_TYPE;
                }        
                return FileContentType;
            }        public string FtpUpload(HttpPostedFile file,string dir)
            {
                string FileDownloadName=DateTime.Now.ToString("yyyyMMddhhmmss")+this.GetFileExtName(file.FileName,true);
                FtpConnection ftp=this.FtpConn();
                if(ftp.DirectoryExist(dir))
                    ftp.SetCurrentDirectory(dir);
                else
                {
                    ftp.CreateDirectory(dir);
                    ftp.SetCurrentDirectory(dir);
                }
                ftp.PutStream(file.InputStream,FileDownloadName);
                ftp.Close();
                return FileDownloadName;
            }        public void FileDel(string filedownloadname,string dir)
            {
                FtpConnection ftp=this.FtpConn();
                if(ftp.DirectoryExist(dir))
                {
                    ftp.SetCurrentDirectory(dir);
                    if(ftp.FileExist(filedownloadname))
                    {
                        ftp.DeleteFile(filedownloadname);
                    }
                }
                ftp.Close();
            }        public void FtpDownload(HttpContext context,string filedownloadname,string dir)
            {
                context.Response.Clear();
                context.Response.AddHeader("Content-Disposition", "attachment; filename="+filedownloadname); 
                context.Response.ContentType=this.GetFileContentType(filedownloadname);
                FtpConnection ftp=this.FtpConn();
                ftp.SetCurrentDirectory(dir);
                if(ftp.FileExist(filedownloadname))
                {
                    FtpStream ftpfs=ftp.OpenFile(filedownloadname,GenericRights.Read);
                    byte [] buffer=new byte[10240];
                    int n=ftpfs.Read(buffer,0,buffer.Length);
                    while(n>0)
                    {
                        context.Response.BinaryWrite(buffer);
                        n=ftpfs.Read(buffer,0,buffer.Length);
                    }
                    Response.End();
                    ftpfs.Close();
                }
                else
                {
                    context.Response.Write("<script>alert('file does not exist!');</script>");
                }
                ftp.Close();
            }
        }
    }