This server-based method is documented in the Visual Studio help files. Open the Help Index, and enter PrintToPrinter in the "Look for:" box. The syntax for this method is:
Report.PrintToPrinter(<copies as int>, <collated as True/False>, <startpage as int>, <endpage as int>)
'Collated' in this context has nothing to do with database collation. Some advanced printers (like copier/printers) will sort each document into its own shelf. Not every printer supports this functionality, so check the printer dialog before setting to true. To print the entire report, set startpage and endpage each to 0.
An example in use might look like
MyReport.PrintToPrinter(1,False,0,0)
One limitation of this method is that a printer name must be specified. You can set the default printer at design time in the report, and you can change the printer name at run time by setting the ReportDocument.PrintOptions.PrinterName pro ......
开发中经常遇到要重置控件值得操作,下面写了常用HTML控件的重置方法。不完整的,大家可以扩充
function ResetControl() {
var v = document.forms[0].elements;
for (var i = 0; i < v.length; i++) {
if (v[i].type == "text") {
v[i].value = "";
} else if (v[i].type == "select-one") {
v[i].options[0].selected = true;
}
} ......
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Data.Common;
using System.Data;
namespace DownData.dal
{
public static class DBHelper
{
private static readonly string connectionString =
"Data Source=.\\newdb;Initial Catalog=downloaddata; uid=sa;pwd=sa";
private static readonly string providerName ="System.Data.SqlClient";
//GetConnection 用于获取连接数据库的 connection 对象...
private static DbConnection GetConnection()
{
DbProviderFactory _factory = DbProviderFactories.GetFactory(providerName);
  ......
1.通过RewritePath实现重写
URL重写可以通过编程的方式来实现。ASP.NET中的Contex.RewritePath()方法可以让你从程序中实现重写请求的URL。一旦重写后,系统将使用新的路径来继续执行这个请求。
在Global.asax文件的Application_BeginRequest()方法中,你需要增加代码来阅读进来的路径,然后根据一个或多个URL重写规则来成需要进一步处理的路径。下面的例子执行以下URL重写规则:
输入的url:"/URLRewriting/OldUrl.aspx 真实访问的url:"/URLRewriting/NewUrl.aspx"
输入的url:"/URLRewriting/UserAccount/{UserId}.aspx 真实访问的url:"/URLRewriting/UserAccount.aspx?id={UserID}
使用Contex.RewritePath()实现URL重写:
void Application_BeginRequest(object sender, EventArgs e)
{
string path=Request.Url.ToString();
if(Regex.IsMatch(path,"WebTest/(.+).aspx",RegexOptions.IgnoreCase))
{
String idString = path.Substring(path.LastIndexOf('/') + 1, path.Length - path.LastIndexOf('/') - 6);
Context.Rewri ......
ASP.NET Cache支持三种类型
想写一个技术快速概述,可能写得太多了。技术概略的目的是以最快最简单的方式描述出技术要点,也是我希望的最有效率的知识传播方式。
1. 页面/控件cache
2. 应用程序级cache
3. 浏览器客户端cache
从实现方式来看,ASP.NET Cache中的页面/控件cache和应用程序级cache都是存放在服务器内存里面的,随着内存的紧张程度,这些内容有可能在失效之前被提前删除。(cache的特性决定这些内容是可以放心得删除掉的)。浏览器客户端的cache是存放在客户端浏览器的cache里面 ,比如IE的临时文件夹就是起的cache的作用。每次用户请求一个页面的时候,浏览器会先从cache里面去查找一下有没有符合要求的还没有过期的cache内容,如果有的话就从cache里面直接读取跳过网络传输。
下面演示一下在ASP.NET里面具体的写法:
1. ASP.NET Cache中的页面/控件cache可以申明在aspx,ascx文件里面,也可以在code behind里面作出申明。
<%@ OutputCache Duration="#ofseconds"
Location="Any | Client | Downstream | Server | None | ServerAndClient "
Shared="True | False"
VaryByControl="controlname"
VaryByCustom="browser | customstri ......
在ASP中,将文件上传到服务器是一件非常麻烦的事情,通常需要第三方组件的支持。
在ASP.NET 1.x 中,要支持文件上传,只须使用HTML的Input(File)控件。把它作为服务器控件运行(手动设置runat="server") ,要直接操作 HttpPostedFile。
在ASP.NET 2.0中,新增了FileUpLoad服务器控件,使得上传更加简单。
包裝了一點點程式碼,我們不用再直接操作 HttpPostedFile,程式稍微簡潔了些。但是其內部還是在操作 HttpPostedFile。真正有價值的差異是 FileUpload 控制項的 FileBytes 屬性。
FileBytes 回傳的是 byte 陣列,等於是幫我們做了序列化,讓檔案上傳機制有了更多可能性,可以更方便的將檔案內容直接轉存到資料庫,或是將檔案傳遞給遠方 WebService 接收 .....
還有 FileBytes 屬性被標記為 Bindable(true),更可以將 FileUpload 控制項輕鬆搭配資料繫結控制項 ......