protected void Page_Load(object sender, EventArgs e)
{
DownFile1(@"D:\常用软件\win7.iso", "win7.iso")
}
private void DownFile1(string filePath, string fileName)
{
ResponseFile(this.Request, this.Response, fileName, filePath, 1024000)
}
// 输出硬盘文件,提供下载
// 输入参数 _Request: Page.Request对象, _Response: Page.Response对象, _fileName: 下载文件名, _fullPath: 带文件名下载路径, _speed 每秒允许下载的字节数
// 返回是否成功
public static bool ResponseFile(HttpRequest _Request, HttpResponse _Response, string _fileName, string _fullPath, long _speed)
{
try
{
FileStream myFile = new FileStream(_fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
BinaryReader br = new BinaryReader(myFile)
try
{
_Response.AddHeader("Accept-Ranges", "bytes")
_Response.Buffer = false
long fileLength = myFile.Length
long startBytes = 0
int pack = 10240//10K bytes
//int sleep = 200 //每秒5次 即5*10K bytes每秒
int sleep = (int)Math.Floor((double)(1000 * pack / _speed)) + 1
if (_Request.Headers["Range"] != null)
{
_Response.StatusCode = 206
string[] range = _Request.Headers["Range"].Split(new char[] { '=', '-' })
startBytes = Convert.ToInt64(range[1])
}
_Response.AddHeader("Content-Length", (fileLength - startBytes).ToString())
if (startBytes != 0)
{
_Response.AddHeader("Content-Range", string.Format(" bytes {0}-{1}/{2}", startBytes, fileLength - 1, fileLength))
}
_Response.AddHeader("Connection", "Keep-Alive")
_Response.ContentType = "application/octet-stream"
_Response.AddHeader("Content-Disposition", "attachmentfilename=" + HttpUtility.UrlEncode(_fileName, System.Text.Encoding.UTF8))
br.BaseStream.Seek(startBytes, SeekOrigin.Begin)
int maxCount = (int)Math.Floor((double)((fileLength - startBytes) / pack)) + 1
for (int i = 0i <maxCounti++)
{
if (_Response.IsClientConnected)
{
_Response.BinaryWrite(br.ReadBytes(pack))
Thread.Sleep(sleep)
}
else
{
i = maxCount
}
}
}
catch
{
return false
}
finally
{
br.Close()
myFile.Close()
}
}
catch
{
return false
}
return true
}
ASP.NET MVC导出Excel首先下载 NPOI.dll 引用到项目中
建议下载地址:http://download.csdn.net/detail/pukuimin1226/5851747
前台代码:
<a href='/Admin/NurseUser/Excel' target='_blank'>导出Excel</a>
后台代码:
//导出excel
public FileResult Excel()
{
//获取list数据
var list = bll.NurseUserListExcel("", "ID asc")
//创建Excel文件的对象
NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook()
//添加一个sheet
NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("Sheet1")
//给sheet1添加第一行的头部标题
NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0)
row1.CreateCell(0).SetCellValue("ID")
row1.CreateCell(1).SetCellValue("用户姓名")
row1.CreateCell(2).SetCellValue("电话")
row1.CreateCell(3).SetCellValue("注册时间")
row1.CreateCell(4).SetCellValue("邀请人ID")
row1.CreateCell(5).SetCellValue("邀请人名称")
row1.CreateCell(6).SetCellValue("邀请人电话")
row1.CreateCell(7).SetCellValue("总积分")
row1.CreateCell(8).SetCellValue("已使用积分")
row1.CreateCell(9).SetCellValue("可用积分")
//将数据逐步写入sheet1各个行
for (int i = 0i <list.Counti++)
{
NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i + 1)
rowtemp.CreateCell(0).SetCellValue(list[i].ID)
rowtemp.CreateCell(1).SetCellValue(list[i].Name)
rowtemp.CreateCell(2).SetCellValue(list[i].Phone)
rowtemp.CreateCell(3).SetCellValue(list[i].CreateTime.Value.ToString())
rowtemp.CreateCell(4).SetCellValue(list[i].InviterID.Value)
rowtemp.CreateCell(5).SetCellValue(list[i].iName)
rowtemp.CreateCell(6).SetCellValue(list[i].iPhone)
rowtemp.CreateCell(7).SetCellValue(list[i].IntegralSum)
rowtemp.CreateCell(8).SetCellValue(list[i].IntegralSy)
rowtemp.CreateCell(9).SetCellValue(list[i].IntegralKy)
}
// 写入到客户端
System.IO.MemoryStream ms = new System.IO.MemoryStream()
book.Write(ms)
ms.Seek(0, SeekOrigin.Begin)
return File(ms, "application/vnd.ms-excel", "用户信息.xls")
}
excel文档就会自动下载下来
下载Microsoft Visual Studio 2010 Uninstall Utility来移除,默认情况下,这将删除 Visual Studio 和支持组件,但不会删除与计算机上的其他应用程序共享的组件。若还要删除共享的组件,则通过/full 开关运行卸载实用程序。若连.NET Framework 4,都移除的话要加 /netfx。1、最快的方法就是下载Microsoft Visual Studio 2010 Uninstall Utility后,单击右键-》发送到-》桌面快捷方式,然后到桌面上,右键单击该快捷方式-》属性-》快捷方式-》内容 的 目标 后面加上 /full /netfx,如下图。
2、然后,双击快捷方式,照着说明一步一步就可以完成卸载了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)