c/s下上传下载word文件! C/S方式下怎么将WORD上传到SQL,并能实现下载。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 上传把文件读成二进制.转化为BASE64编码.保存到SQL数据库中...下载把数据库记录读出.DEBASE64后.转化为二进制写文件... 上传下载的方式,挺多有使用ftp的,还有使用socket(似乎看到socket也用在了ftp传输里面)你看看这个http://www.cnblogs.com/lovecherry/archive/2007/08/06/278459.html 直接保存到NTEXT的数据库字段中就行了 http://support.microsoft.com/kb/309158/zh-cn 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(); } }} 关于在c#中使用word 先加锁,再更新表,再解锁,更不能写成sql语句一次执行? c#中关与事件的问题,请各位进来帮小弟一下,跪谢! 求根据变量生成文件代码 API SetParent()后GetParent()不到值 怎样把字符型百分数转化为浮点型的数值型 多个文本框控件的选定 各位:c#调用dll时数据转换问题.在线..... C#根据句柄获取其缓冲区问题 C#、MVC、EF、Ajax传值找不到地址/错误500 C#中window服务程序是如何退出的? 1.怎样判断用户同时按下了AIT+N键?2.怎样将屏幕上(200,300)那个点设置成红色?
把文件读成二进制.
转化为BASE64编码.保存到SQL数据库中...下载
把数据库记录读出.
DEBASE64后.转化为二进制写文件...
有使用ftp的,还有使用socket(似乎看到socket也用在了ftp传输里面)
你看看这个
http://www.cnblogs.com/lovecherry/archive/2007/08/06/278459.html
{
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();
}
}
}