ASP.NET文件下载函数使用是什么情况呢?在你的Page_Load中添加这样的代码:
Page.Response.Clear();
bool success = ResponseFile(Page.Request, Page.Response, "目的文件名称", @"源文件路径", 1024000);
if (!success) Response.Write("下载文件出错!"); Page.Response.End();
ASP.NET文件下载函数代码为:
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; double pack = 10240;
//10K bytes
//int sleep = 200;
//每秒5次 即5*10K bytes每秒 int sleep = (int)Math.Floor(1000 * pack / _speed) + 1;
if (_Request.Headers["Range"] != null)
{
_Response.StatusCode = 206;
string[] range = _Request.Headers["Range"].Split(new cha ......
string filepath = FileUpload1.FileName; // 得到文件的完整路径
string filename = filepath.Substring(filepath.LastIndexOf("\\") + 1); // 得到文件名(即去掉了路径)
string type = filename.Substring(filename.LastIndexOf(".")); // 得到文件的类型(带 . )
string newname = DateTime.Now.ToString("yyyyMMddHHmmss") + type; // 将当前的时间格式化作为文件的新名字
&nb ......
有时候需要动态的设置 WebService 的址,这样发布到不同的服务器时就要重新生成,为此我们需要在web.config中动态配置WebService的地址,在网上查了很多资料,其中这种方法感觉很好用也很好实现,原文VB.NET实现。本人已改为C#版
首先手动的添加一个Web引用(这个就不用说了吧)
然后修改本地的代理类(添加一个新类,继承你的 WebService代理类)
实例:
namespace Web_Service
{
[System.Diagnostics.DebuggerStepThrough(),System.ComponentModel.DesignerCategory("code"),
System.Web.Services.WebServiceBinding(Name = "", Namespace = "")]
public class DynWebService : SelfWebService
{
public DynWebService() : base()
{
//设置默认webService的地址
this.Url = "http://localhost/WebService.asmx";
}
public DynWebService(string webUrl) : base()
{
this.Url = webUrl;
}
}
}
说明:SelfWebService 你引用的 WebService
Web Service的URI部署到配置文件里
<add key="WebServiceKey"value="http://xxxx/WebSe ......
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<!-- 动态调试编译
设置 compilation debug="true" 以将调试符号(.pdb 信息)插入到编译页中。因为这将创建执行起来较慢的大文件,所以应该只在调试时将该值设置为 true,而所有其他时候都设置为false。有关更多信息,请参考有关调试 ASP.NET 文件的文档。
-->
<compilation defaultLanguage="vb" debug="true" />
<!-- 自定义错误信息
设置 customErrors mode="On" 或 "RemoteOnly" 以启用自定义错误信息,或设置为 "Off" 以禁用自定义错误信息。为每个要处理的错误添加 <error> 标记。
-->
<customErrors mode="RemoteOnly" />
<!-- 身份验证
此节设置应用程序的身份验证策略。可能的模式是 \“Windows\”、\“Forms\”、“Passport\”和 \“None\”
-->
<authentication mode="Windows" />
<!-- 授权
此节设置应用程序的授权策略。可以允许或拒绝用户或角色访问应用程序资源。通配符:"*" 表示任何人,"?" 表示匿名(未授权的)用户。
-->
<au ......
ASP.NET中多国语言的实现
http://www.cnblogs.com/firstyi/archive/2008/03/13/1103970.html
ASP.NET缓存提高站点性能
http://www.cnblogs.com/firstyi/archive/2007/08/15/856676.html
客户端脚本管理
http://www.cnblogs.com/firstyi/archive/2006/11/13/559049.html ......
1:Gridview中的内容导出到Excel
Asp.net 2.0中新增的gridview控件,是十分强大的数据展示控件,在前面的系列文章里,分别展示了其中很多的基本用法和技巧。在本文中,将继续探讨有关的技巧。
一、Gridview中的内容导出到Excel
在日常工作中,经常要将gridview中的内容导出到excel报表中去,在asp.net 2.0中,同样可以很方便地实现将整个gridview中的内容导出到excel报表中去,下面介绍其具体做法:
首先,建立基本的页面default.aspx
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>
<br/>
<asp:Button ID="BtnExport" runat="server" OnClick="BtnExport_Click"
Text="Export to Excel" />
</form>
在default.aspx.cs中,写入如下代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindData();
}
}
private void BindData()
{
string query = "SELECT * from customers";
SqlConnection myConnection = new SqlConnection(ConnectionString);
SqlDataAdapter ad = new SqlDataAdap ......