【.net实现文件跨服务器上传文件】.NET实现文件跨服务器上传下载的教程

更新时间:2020-12-16    来源:J2EE/EJB/服务器    手机版     字体:

【www.bbyears.com--J2EE/EJB/服务器】

环境说明

两台服务器服务器为A,服务器为B,服务器B为文件服务器

实现方法

1、在A和B上创建用户docshareuser,用户名和密码保持一致

2、B服务器上设置附件文件夹Attachments共享,添加用户docshareuser并设置读写权限

 

3、在A上运行框输入”\\IP\Attachments”,输入用户名密码测试是否共享成功,共享不成功请检查网络及配置问题

4、修改AWeb.config文件附件路径节点的值

5、在节点下添加如下配置,用户名密码与创建的共享帐号保持一致

word="密码"/>

测试上传成功!下载时报错:

因为下载的方法如下:

context.Response.AppendHeader("Content-Length", fileSize.ToString()); context.Response.CacheControl = HttpCacheability.Public.ToString(); context.Response.Cache.AppendCacheExtension("max-age="+ 365 * 24 * 60 * 60); context.Response.Cache.SetExpires(DateTime.Now.AddYears(1)); context.Response.AppendHeader("ETag","Never_Modify"); context.Response.Cache.SetETag("Never_Modify"); context.Response.Cache.SetLastModified(DateTime.Now.AddMinutes(-1));    context.Response.TransmitFile(filePath);

修改下载方式:

FileStream fs =newFileStream(filePath, FileMode.Open);     byte[] bytes =newbyte[(int)fs.Length];     fs.Read(bytes, 0, bytes.Length);     fs.Close();     Response.ContentType ="application/octet-stream";     //通知浏览器下载文件而不是打开     Response.AddHeader("Content-Disposition","attachment; filename="+ HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));     context.Response.BinaryWrite(bytes);     context.Response.Flush();     context.Response.End();

本文来源:http://www.bbyears.com/jsp/116870.html