以往写windows service都需要个ProjectInstaller和serviceInstaller并配置serviceName,这样build出来的exe在install成windows service时我们会:
@echo 安装WindowService
@Set Path=C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;
@Set svn_dir=%cd%
installutil %svn_dir%\MyServiceDemo.exe
pause
@echo 成功!
但服务名被我们编译在程序里了,如果这个exe想被装很多次服务怎么办呢?
今天从同事Martin Jia那里学来一个好方法,可以不用ProjectInstaller、serviceInstaller这种东西,直接安装exe为windows service并在安装时指定服务名称
阅读剩余部分...
使用如下代码可以发送附件
MailMessage mail = new MailMessage();
mail.To = "me@mycompany.com";
mail.From = "you@yourcompany.com";
mail.Subject = "this is a test email.";
mail.Body = "this is my test email body.";
MailAttachment attachment = new MailAttachment( Server.MapPath( "mailTest.txt" ) ); //create the attachment
mail.Attachments.Add( attachment );
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send( mail );
使用如下代码可以在用户上传附件后发生邮件:
阅读剩余部分...
今天在帮同事调程序时发现了这个死角
现象如下,没有任何输入的textarea提交到服务端后得到的值总是","
找了半天发现是因为页面上两个textarea的name相同,以前只知道页面上radio的name相同则是一个组,name相同的
的checkbox提交后是以逗号分隔值的,于是做了下面代码的试验,发现任何name相同的element提交到服务端都会得到逗号分隔的值,以前还不知道这个,汗
阅读剩余部分...
如何深度克隆一个对象?
普通版:
public static object CloneObject( object obj )
{
using ( MemoryStream memStream = new MemoryStream( ) )
{
BinaryFormatter binaryFormatter = new BinaryFormatter( null ,
new StreamingContext( StreamingContextStates.Clone ) );
binaryFormatter.Serialize( memStream , obj );
memStream.Seek( 0 , SeekOrigin.Begin );
return binaryFormatter.Deserialize( memStream );
}
}
泛型版:
阅读剩余部分...
posted on
September 18, 2004
要在后台把CheckBoxList的某个ListItem 的selected给true了
遍历该CheckBoxList,写下了下面注释内的代码,死活不能选中我的第个CheckBox
string bigClassId = ( ( DataRowView)e.Item.DataItem )["模块编号"].ToString();
string bigClassName = ( ( DataRowView)e.Item.DataItem )["模块名称"].ToString();
CheckBoxList chk_list_big = (CheckBoxList)e.Item.FindControl("chk_list_big") as CheckBoxList;
if(chk_list_big != null)
{
chk_list_big.Items.Clear();
ListItem item = new ListItem();
item.Text = bigClassName;
item.Value = bigClassId;
chk_list_big.Items.Add(item);
chk_list_big.Attributes["onclick"] = String.Format("CheckAll('{0}')",chk_list_big.ClientID);
//将符合用户模块的ListItem选定
for(int i=0; i<this.taxiUser.Modules.Length; i++)
{
if( bigClassId == this.taxiUser.Modules[i] )
{
chk_list_big.Items.FindByValue(this.taxiUser.Modules[i]).Selected = true;
}
}
//真是见了鬼了!为什么用这样的方法不能选定该ListItem???// foreach(ListItem listItem in chk_list_big.Items)
// {
// if(Array.IndexOf(this.taxiUser.Modules,listItem.Value) > 0)
// {
// listItem.Selected = true;
// }
// }半天不能醒悟就想着换道道,写了”该死”那行上面的几行代码把数组放倒来,(站着不行我就躺着来),发现可行,然后就开始发楞,命名原理一摸一样的啊,真是“见鬼”,对者这几行代码发了会愣,就决定

还要狠狠的

,
if (Array.IndexOf(xxxxx) > 0) 用力


吧

555555,撞的头都疼了.






posted on
August 21, 2004
写法1
if ( 条件1 && 条件2)
{
//代码
}
写法2
if ( 条件1 )
{
if( 条件2 )
{
//代码
}
}
我一直认为写法1要比写法2条理清晰,容易阅读.
不知其他人如何认为呢?
今天在微软的KB中阅读 使用 Visual Basic .NET 在采用基于表单身份验证的 ASP.NET 应用程序中实现基于角色的安全性 的时候
发现这样的写法
而且这则KB的VB版本也是这样的写的.
这样写有优越性?