人生是一场不能存盘的RPG,我只能尽量多搞几个Screenshot

March 21, 2007

Using Configuration.Section to access subsection

Filed under: .NET, Code snippets

Using Configuration.Section to access subsection
Copy from http://geekswithblogs.net/mnf/archive/2006/05/12/77981.aspx

I have a section in Web.Config:

<applicationSettings>

<FSBsnsCsLib.Properties.Settings>

</FSBsnsCsLib.Properties.Settings>

</applicationSettings>

I’ve tried to access inner section using shortcut “Section/Subsection”

string sSectionName=”applicationSettings/FSBusinessLib.My.MySettings”;
System.Configuration.ClientSettingsSection sectSettings = (ClientSettingsSection)config.Sections[sSectionName];

but it returned null.

The correct way is the following:

conststringcnstApplicationSection = “applicationSettings”;
ConfigurationSectionGroupgrpApplicationSection = config.SectionGroups[cnstApplicationSection];
string sSectionName=”FSBusinessLib.My.MySettings”;
System.Configuration.ClientSettingsSection sectSettings = grpApplicationSection .Sections[sSectionName];

March 9, 2007

用户名Regex

Filed under: Regular Expression

只接受非空的输入,可由字符,音标,数字,空格,括号等组成, 不能以空格开头.
“^[\p{L}\p{Mn}\p{N}\p{Pc}\p{Po}\p{Ps}\p{Pe}\p{Pd}]+[\p{L}\p{Mn}\p{Zs}\p{N}\p{Pc}\p{Po}\p{Ps}\p{Pe}\p{Pd}]?$”

\p{L} - Allows all letters

\p{Mn} - Allows non-spacing marks including accents and umlauts

\p{Zs} - Allows space separator characters including normal space

\p{N} - Allows all numbers

\p{Ps} - Allows all Open characters such as {, ( and [ but not <

\p{Pe} - Allows all Close characters such as }, ) and ] but not >

\p{Sm} - Allows all math characters

\p{Pc} - represent connection punctuation, such as “_”,

\p{Po} - represent punctuations.

\p{Pd} - Dashes and hyphens.

March 7, 2007

.net2.0 自带的压缩/解压类GZipStream Class

Filed under: .NET, Code snippets

http://www.codeguru.com/csharp/.net/net_data/sortinganditerating/article.php/c13375/
http://msdn2.microsoft.com/en-us/library/system.io.compression.gzipstream.aspx

支持gzip格式(见RFC 1952),生成的压缩文件后缀为.gz,不能压缩大于4GB的文件
和XP内置的zip格式不兼容

//–压缩
FileStream fs = new FileStream(”es_resume.doc”, FileMode.Open);
byte[] input = new byte[fs.Length];
fs.Read(input, 0, input.Length);
fs.Close();

FileStream fsOutput = new FileStream(”es_resume.gzip”,
FileMode.Create,
FileAccess.Write);
GZipStream zip = new GZipStream(fsOutput, CompressionMode.Compress);

zip.Write(input, 0, input.Length);
zip.Close();
fsOutput.Close();

//–解压
FileStream fs = new FileStream(”es_resume.gzip”, FileMode.Open);
FileStream fsOutput = new FileStream(”es_resume2.doc”,
FileMode.Create,
FileAccess.Write);
GZipStream zip = new GZipStream(fs, CompressionMode.Decompress, true);

byte[] buffer = new byte[4096];
int bytesRead;
bool continueLoop = true;
while (continueLoop)
{
bytesRead = zip.Read(buffer, 0, buffer.Length);
if (bytesRead == 0)
break;
fsOutput.Write(buffer, 0, bytesRead);
}
zip.Close();
fsOutput.Close();
fs.Close();

March 6, 2007

Parse IIS log using MS Log Paser2.2 in c#

Filed under: Uncategorized

http://www.codeproject.com/csharp/SimpleLogParse.asp
Download and install Log parser 2.2 from Microsoft
Add a reference to LogParser.dll in the installation directory
using MSUtil;

IIS 7

Filed under: ASP.NET

出自:IIS 7.0 探索用于 Windows Vista 的 Web 服务器和更多内容

1> IIS 7.0 的核心完全模块化,由 40 多项功能组成,这些功能基于一个新的可扩展层,这个层
允许.NET Framework 来扩展或替换。

2> IIS元数据被基于分布式 XML 配置文件applicationHost.config 文件替换.该文件包含服务器级
别的配置默认设置.在 IIS 7.0 中,配置系统是完全可扩展的。新模块可以添加它们自己的配置
架构,从而使应用程序能够与 IIS 和 ASP.NET一起配置其功能

3>新的图形化 IIS 管理器管理工具取代了InetMgr.exe MMC 管理单元.可将自定义管理 UI 添加到工具中
http://iis.net/default.aspx?tabid=7&subtabid=73
IIS 7.0 提供了 appcmd.exe 命令行工具
http://iis.net/default.aspx?tabid=2&subtabid=25&i=954&p=1

4>可以利用 Microsoft.Web.Administration API 通过 .NET 应用程序管理IIS
iis.net/default.aspx?tabid=2&subtabid=25&i=1076。

5>在 IIS 7.0 中,ASP.NET 有两个版本:经典模式和集成模式。
经典模式的工作方式与它在以前版本的 IIS 中完全相同。
集成模式是新的平台默认设置,它使用全新的引擎来提供与 IIS Web 服务器前所未有的集成。
在集成模式下,可以用 ASP.NET API 开发 IIS 7.0 模块,这样的模块可以直接与 Web 服务
器集成,并且能够提供用基本 C++ API 即可实现的几乎所有服务。
http://mvolo.com/2006/11/10/stopping-hotlinking-with-iis-and-aspnet.aspx

6>URL 授权与 ASP.NET 2.0 成员身份和角色管理功能无缝集成在一起

7>新的XML日志文件

8>通过 appcmd.exe 命令行工具或使用 Microsoft.Web.Administration API 以编程方式访问
服务器的实时状态

9>Windows Vista 上的 IIS 受限于每次 10 个并发请求

宏: Visual Studio 2005 IDE 技巧和窍门

Filed under: Visual Studio

Visual Studio 2005 IDE 技巧和窍门

http://www.microsoft.com/china/msdn/library/langtool/vs2005/bb245788.mspx?mfr=true
1. 使用宏列举出所有的快捷键,导入配置文件

2.编辑快捷键的配置文件
My Documents\Visual Studio 2005\Settings\MyKeyboardShortcuts.vssettings

3.使用宏快速切换窗口布局,并将宏添加到ToolBar上.

4.Using team setting.file

5.Reset vs 的配置
devenv.exe /resetuserdata

March 3, 2007

Image Resource

Filed under: Uncategorized

如果在from中使用了一个image,以前的做法是直接通过文件系统来访问这个资源,或是把image作为resoruce嵌入到Assembly中,后者会对Assembly的加载带来负面影响.
在.net2.0中,在使用Image时可以选择使用Local Resource或是Project reouce File,如果使用Local reource,
就会按老路,在resource中添加Image的内容,然后把reouce嵌入到Assembly中.
如果使用Project resouce File,就会生成所谓的Strong type resouce.
1.把Image copy到project所在的路径\Resources
2.生成Project一级的Resouce File:
Resources.resx 记录resource的type和path
<data name=”Winter” type=”System.Resources.ResXFileRef, System.Windows.Forms”>
<value>..\Resources\Winter.jpg;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
Resource.Designer.cs,生成代码来访问resouce:
internal static System.Drawing.Bitmap Winter
{
get {
object obj = ResourceManager.GetObject(”Winter”, resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}

在.net2.0中,Project级的resource存在于Solution Explorer的Proertires目录下,
可以可视化的编辑这个resource,添加string, icon, image,file等类型的resource
VS2005会在Resource.Designer.cs自动生成强类型的resouce,调用的语句如:
this.Icon = <NameSpace>Properties.Resources.<ResourceName>

UserSetting的读写

Filed under: Uncategorized

在.net2.0中,Project级的resource存在于Solution Explorer的Proertires目录下有一个
名为Setting.settings的文件.在此处声明用户配置会在Setting.Designer.cs中生成相关
代码,读写用户配置:
The developer can enter setting information directly into Visual Studio, choosing a name, scope (User/Application), type and optional value. Strongly-typed classes are generated that provide programmatic access to the settings, as well as load and save operations that manipulate settings in the user’s Local Settings\Application Data folder.

private void LoadRecentUrls()
{
String recentUrlsXml = Properties.Settings.Default.RecentUrls;

if (!string.IsNullOrEmpty(recentUrlsXml))
{
XmlSerializer xs = new XmlSerializer(typeof(List<UrlInfo>));
List<UrlInfo> urlInfos = (List<UrlInfo>)xs.Deserialize(new StringReader(recentUrlsXml));

foreach (UrlInfo urlInfo in urlInfos)
{
recentUrlsMenuItem.DropDownItems.Add(new UrlMenuItem(urlInfo));
}

recentUrlsMenuItem.Enabled = true;
}
}
private void SaveRecentUrls()
{
List<UrlInfo> urlInfos = new List<UrlInfo>();

foreach (UrlMenuItem menuItem in recentUrlsMenuItem.DropDownItems)
{
urlInfos.Add(menuItem.UrlInfo);
}

XmlSerializer xs = new XmlSerializer(typeof(List<UrlInfo>));
StringWriter sw = new StringWriter();
xs.Serialize(sw, urlInfos);

Properties.Settings.Default.RecentUrls = sw.ToString();
Properties.Settings.Default.Save();
}

// 在没有这个之前,我使用了:
private void ReadRecentFiles()
{
ConnectionStringsSection section = (ConnectionStringsSection)ConfigurationManager.GetSection(”connectionStrings”);
//I must use <clear/> in <connectionStrings>.
//Or, a defualt sql connection string will be read.
for (int i = 0; i < section.ConnectionStrings.Count; i++)
{
FileInfo fileInfo = new FileInfo(section.ConnectionStrings[i].ConnectionString);
}
private void SaveRecentFiles()
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConnectionStringsSection appSection = (ConnectionStringsSection)config.GetSection(”connectionStrings”);

appSection.ConnectionStrings.Clear();

int count = Math.Min(this.recentFiles.Count, this.recentFilesCount);
for (int i = 0; i < count; i++)
{
FileInfo file = new FileInfo(this.recentFiles[i]);
appSection.ConnectionStrings.Add(new ConnectionStringSettings(file.Name, file.FullName));
}

config.Save();
}

March 2, 2007

WM_POPUPSYSTEMMENU message

Filed under: .NET

在task bar上点击鼠标右键,会弹出system menu,此消息为:
WM_POPUPSYSTEMMENU(0x313)






















Get free blog up and running in minutes with Blogsome
Theme designed by Hadley Wickham