
Visual CSharp 2005 Recipes (2006) [eng]
.pdf
548 ■I N D E X
OleDbConnection class |
OpenReadAsync method |
example, 302 |
WebClient class, 341 |
System.Data.OleDb namespace, 301 |
OpenReadCompleted event |
OleDbConnectionStringBuilder class |
WebClient class, 341 |
System.Data.OleDb namespace, 307 |
OpenRemoteBaseKey method |
OleDbDataReader class |
RegistryKey class, 509 |
System.Data.OleDb namespace, 319 |
OpenSubKey method |
OleDbFactory class |
RegistryKey class, 509 |
System.Data.OleDb namespace, 329 |
OpenText method |
OleDbParameter class |
FileInfo class, 149 |
System.Data.OleDb namespace, 315 |
OpenWrite method |
OnClosed method |
FileInfo class, 149 |
Form class, 223 |
OperatingSystem class |
OnClosing method |
properties, 501 |
Form class, 223 |
System namespace, 500 |
OnContinue method |
OperationalStatus enumeration |
ServiceBase class, 512 |
System.Net.NetworkInformation namespace, |
OnCustomCommand method |
337 |
ServiceBase class, 513 |
values, 337 |
OnDeserializedAttribute class, 459 |
OperationalStatus property |
OnDeserializingAttribute class, 459 |
NetworkInterface class, 337 |
OnKeyPress method |
optional parameters |
ComboBox control, 232 |
passing by reference, 453 |
OnLoad method |
optional permission request, 402 |
Form class, 223 |
OptionalFieldAttribute class |
OnPause method |
System.Runtime.Serialization namespace, |
ServiceBase class, 512 |
459 |
OnPowerEvent method |
Options property |
ServiceBase class, 512 |
RegexCompilationInfo class, 46 |
OnSerializedAttribute class, 459 |
Options value |
OnSerializingAttribute class, 459 |
RegexOptions enumeration, 46 |
OnSessionChange method |
OR (|) arithmetic operator, 147 |
ServiceBase class, 513 |
OR operator ||, 13 |
OnShutdown method |
OracleClientFactory class |
ServiceBase class, 512 |
System.Data.OracleClient namespace, 329 |
OnStart method |
OracleCommand class |
ServiceBase class, 512 |
System.Data.OracleClient namespace, 311 |
OnStop method |
OracleConnection class |
ServiceBase class, 512 |
System.Data.OracleClient namespace, 301 |
OnTextChanged method |
OracleConnectionStringBuilder class |
ComboBox control, 232 |
System.Data.OracleClient namespace, 307 |
Open method |
OracleDataReader class |
connection objects, 302 |
methods, 320 |
FileInfo class, 149 |
System.Data.OracleClient namespace, 319 |
OpenExeConfiguration method |
OracleParameter class |
ConfigurationManager class, 309 |
System.Data.OracleClient namespace, 315 |
OpenExisting method |
OSVersion property |
EventWaitHandle class, 121 |
Environment class, 500 |
OpenFileDialog class |
OSVersionInfo class |
CheckFileExists property, 172 |
defining with explicit layout, 445 |
FileName property, 172 |
OuterXml property |
Filter property, 172 |
XmlNode class, 184 |
Multiselect property, 172 |
Output value |
setting filter string, 173 |
ParameterDirection enumeration, 316 |
System.Windows.Forms namespace, 172 |
overloading methods |
OpenForms property |
.NET Framework, 453 |
Application class, 220 |
OverwritePrompt property |
OpenRead method |
SaveFileDialog class, 173 |
FileInfo class, 149 |
Owner property |
WebClient class, 341, 344 |
IVideoWindow interface, 279 |


550 ■I N D E X
PlaySync method |
PrintPreviewDialog class |
SoundPlayer class, 276 |
Document property, 292 |
PolicyException class, 401 |
Show method, 292 |
System.Security.Policy namespace, 400, 415 |
System.Windows.Forms namespace, 292 |
polling |
PrintTestPage method |
determining if asynchronous methods are |
Win32_Printer class, 298 |
finished, 325 |
PrivateBinPath property |
Port property |
AppDomainSetup class, 66 |
SmtpClient class, 352 |
Process class, 135–136 |
position function, 196 |
CloseMainWindow method, 138–139 |
PowerUser value |
Handle property, 442 |
WindowsBuiltInRole enumeration, 413 |
HasExited property, 139 |
Prefixes property |
Kill method, 138 |
HttpListener class, 346 |
MainWindowHandle property, 442 |
primary interop assembly. See PIA |
methods, 138 |
PrincipalPermission class |
Start method, 135–136 |
System.Security.Permissions namespace, 414 |
System.Diagnostics namespace, 135, 442 |
PrincipalPermissionAttribute class |
WaitForExit method, 137, 139 |
System.Security.Permissions namespace, 414 |
processes, 95–96 |
PrincipalPolicy enumeration |
starting a new process, 134–138 |
System.Security.Principal namespace, 415 |
terminating a process, 138–140 |
values, 415 |
ProcessInfo class |
PrintDialog class, 282 |
System.Diagnostics namespace, 135 |
attaching to PrintDocument class, 285 |
ProcessorCount property |
Document property, 285 |
Environment class, 500 |
System.Windows.Forms namespace, 285 |
ProcessStartInfo class |
PrintDocument class, 282, 292 |
properties, 136–137 |
attaching PrintDialog class, 285 |
System.Diagnostics namespace, 433 |
BeginPrint event, 284 |
ProcessWindowStyle enumeration |
custom class inheriting from, 287–288 |
System.Diagnostics namespace, 136 |
DefaultPageSettings property, 285 |
values, 136 |
EndPrint event, 284 |
Programming .NET Security |
PrinterSettings property, 285 |
Adam Freeman and Allen Jones, 394 |
PrintPage event, 284–285, 287–288 |
Protect method |
System.Drawing.Printing namespace, 284 |
ProtectedMemory class, 436 |
PrinterName property |
ProtectedData class |
PrinterSettings class, 282 |
example, 436–437 |
PrinterSettings class |
System.Security.Cryptography namespace, |
InstalledPrinters collection, 282 |
435 |
PrinterName property, 282 |
Unprotect method, 435 |
System.Drawing.Printing namespace, 282 |
ProtectedMemory class |
PrinterSettings property |
Protect method, 436 |
PrintDocument class, 285 |
System.Security.Cryptography namespace, |
printing, 257 |
435 |
managing print jobs, 295–298 |
Unprotect method, 435 |
printing multipage document, 287–290 |
ProtectSection method |
printing simple document, 284–287 |
SectionInformation class, 309 |
printing wrapped text, 290–292 |
ProviderName property |
retrieving information about printers, |
ConnectionStringSettings class, 309 |
282–284 |
Publisher class |
showing a dynamic print preview, 292–295 |
System.Security.Policy namespace, 408 |
PrintOperator value |
PublisherIdentityPermission class, 408 |
WindowsBuiltInRole enumeration, 413 |
System.Security.Permissions namespace, |
PrintPage event |
408 |
PrintDocument class, 284–285, 287–288 |
PublisherIdentityPermissionAttribute class, |
PrintPageEventArgs class |
408 |
HasMorePages property, 287–288 |
Pulse method |
PrintPreviewControl class |
Monitor class, 117 |
Document property, 293 |
PulseAll method |
System.Windows.Forms namespace, 292 |
Monitor class, 117 |


552 ■I N D E X
regular expressions |
restrictions on users |
commonly used regular expressions, 43 |
extending and overriding members, 407–409 |
using compiled regular expressions, 45–47 |
Resume method |
validating input, 41–44 |
Win32_Printer class, 295 |
relative paths, 168–169 |
Win32_PrintJob class, 295 |
Release method |
ResumeLayout method |
Semaphore class, 126 |
Control class, 215 |
ReleaseComObject method |
retrieving |
Marshal class, 452 |
handles, 444 |
ReleaseMutex method |
unmanaged error information, 450 |
Mutex class, 124 |
ReturnValue value |
remoting |
ParameterDirection enumeration, 316 |
as successor to DCOM, 335 |
ReverseString method |
controlling lifetime of remote objects, |
StringBuilder class, 32 |
388–390 |
RichTextBox class, 173 |
controlling versioning of remote objects, |
RIPEMD160Managed class |
390–391 |
System.Security.Cryptography namespace, |
creating remotable objects, 381–385 |
424 |
hosting remote objects in IIS, 387–388 |
RNGCryptoServiceProvider class |
registering remotable objects in assembly, |
as wrapper for CryptGenRandom function, |
385–387 |
421 |
RemotingConfiguration class |
example, 422 |
Configure method, 381 |
System.Security.Cryptography namespace, |
RegisterWellKnownServiceType method, |
421 |
385 |
role-based security, 393 |
System.Runtime.Remoting namespace, 381 |
Root property |
RemoveAt method |
DirectoryInfo class, 144 |
SecureString class, 432 |
RowCount property |
Renamed event |
TableLayoutPanel container, 238 |
FileSystemWatcher class, 176 |
RsaProtectedConfigurationProvider class, 309 |
RenamedEventArgs class, 177 |
Run method |
Renew method |
ServiceBase class, 511, 515 |
ILease interface, 389 |
Run method |
RenewOnCallTime property |
Application class, 4 |
ILease interface, 389 |
RunInstallerAttribute class |
Replace method |
System.ComponentModel namespace, 516 |
FileInfo class, 149 |
Running method |
Replicator value |
ThreadState class, 113 |
WindowsBuiltInRole enumeration, 413 |
runtime callable wrapper. See RCW |
ReplyTo property |
runtime environment information |
MailMessage class, 353 |
accessing, 499–503 |
Request property |
■S |
HttpListenerContext class, 346 |
|
RequestAdditionalTime method |
SameLogon value |
ServiceBase class, 512 |
MemoryProtectionScope enumeration, |
RequestHandler method |
436 |
HttpListener class, 347 |
SameProcess value |
RequestMinimum value |
MemoryProtectionScope enumeration, |
SecurityAction enumeration, 401 |
436 |
RequestRefuse value |
Save method |
SecurityAction enumeration, 403 |
IWshShortcut interface, 518 |
Reset method |
XmlDocument class, 188 |
IEnumerator interface, 475 |
SaveFileDialog class |
ManualResetEvent class, 121 |
CreatePrompt property, 173 |
ResetAbort method |
FileName property, 173 |
Thread class, 132 |
OverwritePrompt property, 173 |
ResetColor method |
setting filter string, 173 |
Console class, 29 |
System.Windows.Forms namespace, 172 |
Response property |
SavePolicy method |
HttpListenerContext class, 346–347 |
SecurityManager class, 398, 400 |

■I N D E X 553
schemas |
SecurityAction enumeration |
creating for .NET classes, 207–208 |
InheritanceDemand value, 407 |
generating a class from, 208–209 |
RequestMinimum value, 401 |
validating documents against a schema, |
System.Security.Permissions namespace, 403 |
199–204 |
SecurityEnabled property |
Schemas property |
SecurityManager class, 397 |
XmlDocument class, 204 |
SecurityException class |
schemas, XML. See XML schemas |
System.Security namespace, 400, 404, 407, 414 |
SCM (Windows Service Control Manager) |
SecurityIdentifier class |
methods and properties inherited from |
System.Security.Principal namespace, 412 |
ServiceBase class, 512 |
SecurityManager class |
screen capture, performing, 270–271 |
CheckExecutionRights property, 398–400 |
scrollable image |
IsGranted method, 406–407 |
creating, 268–270 |
SavePolicy method, 398, 400 |
SearchOption enumeration, 163 |
SecurityEnabled property, 397 |
AllDirectories value, 163 |
System.Security namespace, 397, 406 |
SectionInformation class |
SecurityPermission class, 401 |
ConnectionStringsSection collection, |
ControlPolicy element, 397, 399 |
309 |
ControlPrincipal element, 415, 418 |
ProtectSection method, 309 |
Execution element, 399 |
Unprotect method, 309 |
System.Security.Permissions namespace, 58, |
SecureString class |
397, 398 |
AppendChar method, 432 |
Select method |
Clear method, 433 |
Certificates class, 376 |
Dispose method, 433 |
SelectedPath property |
InsertAt method, 432 |
FolderBrowserDialog class, 173 |
MakeReadOnly method, 432 |
SelectFromCollection method |
RemoveAt method, 432 |
X509Certificate2UI class, 350 |
SetAt method, 432 |
SelectNodes method |
System.Security namespace, 432 |
XmlDocument class, 194 |
ToString method, 432 |
XmlNode class, 194 |
security, 393–394 |
SelectSingleNode method |
allowing partially trusted code to use strong- |
XmlDocument class, 194 |
named assemblies, 394–396 |
XmlNode class, 194 |
determining at runtime if code has specific |
Sells, Chris |
permission, 406–407 |
RegExDesigner.NET, 42 |
determining if user is member of Windows |
Semaphore class |
group, 411–414 |
Release method, 126 |
disabling code access security, 396–398 |
System.Threading namespace, 126 |
disabling execution permission checks, |
used as a trigger, 111 |
398–400 |
Send method |
ensuring runtime grants specific permissions |
MailMessage class, 353 |
to assembly, 400–402 |
Ping class, 357 |
impersonating a Windows user, 418–421 |
SendAsync method |
inspecting assembly’s evidence, |
MailMessage class, 353 |
409–411 |
Ping class, 357 |
limiting permissions granted to assembly, |
SendCompleted event |
402–403 |
MailMessage class, 353 |
optional permission request, 402 |
sequential layout |
refuse request, 402 |
defined, 445 |
restricting which user can execute code, |
serializable types |
414–418 |
implementing, 457–463 |
restricting who can extend classes and |
storing to a file, 58–61 |
override members, 407–409 |
SerializableAttribute class, 458 |
viewing permissions required by assembly, |
implementing ISerializable interface, 459 |
403–406 |
System namespace, 72, 458, 488, 491 |
working with security-sensitive strings in |
serialization |
memory, 432–435 |
attributes, 459 |
Security value |
XML serialization with custom objects, |
NotifyFilters enumeration, 177 |
204–207 |

554 ■I N D E X
SerializationException class |
SetWindowSize method |
System.Runtime.Serialization namespace, 81 |
Console class, 29 |
SerializationInfo class, 459 |
SHA1CryptoServiceProvider class |
AddValue method, 459 |
System.Security.Cryptography namespace, |
GetXXX methods, 460 |
424 |
Serialize method |
SHA1Managed class |
BinaryFormatter class, 58 |
System.Security.Cryptography namespace, |
IFormatter interface, 58 |
424 |
SoapFormatter class, 58 |
SHA256Managed class |
SerialPort class |
System.Security.Cryptography namespace, |
System.IO.Ports namespace, 179 |
424 |
ServiceBase class |
SHA384Managed class |
methods, 512 |
System.Security.Cryptography namespace, |
properties, 512–513 |
424 |
RequestAdditionalTime method, 512 |
shallow copy, 463 |
Run method, 511, 515 |
shapes, hit testing, 259–263 |
System.ServiceProcess namespace, 511 |
shared data, synchronizing access to, 128–130 |
ServiceDependsUpon property |
Shift value |
ServiceInstaller class, 516 |
ConsoleModifiers enumeration, 62 |
ServiceInstaller class |
shortcuts, creating on Desktop or Start menu, |
properties, 516 |
518–520 |
ServiceName property |
Show method |
ServiceBase class, 513 |
MessageBox class, 217 |
ServiceInstaller class, 516 |
PrintPreviewDialog class, 292 |
ServicePack property |
Sign Tool |
OperatingSystem class, 501 |
signing assemblies with Authenticode, 22–25 |
ServiceProcessInstaller class |
supersedes File Signing tool, 22 |
System.ServiceProcess namespace, 516 |
SignalAndWait method |
SessionChangeDescription class |
WaitHandle class, 121 |
System.ServiceProcess namespace, 513 |
simple types |
Set method |
XML schemas, 200 |
AutoResetEvent class, 121 |
SingleCall value |
ManualResetEvent class, 121 |
WellKnownObjectMode enumeration, 385 |
Set Registry tool, 27 |
Singleton pattern |
SetAccessControl method |
implementing, 492–493 |
File class, 180 |
Singleton value |
SetAt method |
WellKnownObjectMode enumeration, 385 |
SecureString class, 432 |
Site class |
SetCurrentDirectory method |
System.Security.Policy namespace, 408 |
Directory class, 168 |
SiteIdentityPermission class |
SetData method |
System.Security.Permissions namespace, 408 |
AppDomain class, 80–81 |
Size value |
SetDefaultPrinter method |
NotifyFilters enumeration, 177 |
Win32_Printer class, 298 |
SizeChanged event |
SetLastError field |
PictureBox control, 280 |
DllImportAttribute class, 448 |
SizeOf method |
SetMaxThreads method |
Marshal class, 444–445 |
ThreadPool class, 99 |
SMTP, sending email, 351–355 |
SetPrincipalPolicy method |
SmtpClient class |
AppDomain class, 415 |
example, 353, 355 |
setreg.exe, 27 |
properties, 352 |
SetStyle method |
System.Net.Mail namespace, 352 |
Form class, 271 |
sn.exe. See Strong Name tool |
SetThreadPrincipal method |
SoapFormatter class, 60 |
AppDomain class, 415 |
Deserialize method, 58 |
SetValue method |
Serialize method, 58 |
Registry class, 506 |
System.Runtime.Serialization.Formatters. |
RegistryKey class, 510 |
Soap namespace, 58, 205 |
SetWindowPosition method |
SocketPermission class, 401 |
IVideoWindow interface, 279 |
System.Net namespace, 400 |

■I N D E X 555
SocketPermissionAttribute class, 401 |
SqlDataReader class |
Software Publisher Certificate Test tool |
methods, 320 |
generating SPC from X.509 certificate, 25 |
System.Data.SqlClient namespace, 319 |
Software Publisher Certificate, 25-27 |
SqlDataSourceEnumerator class, 332 |
Sort method |
GetDataSources method, 331 |
Array class, 51 |
Instance property, 332 |
ArrayList class, 51, 468 |
System.Data.SqlClient namespace, 331 |
ListView control, 235 |
SqlParameter class |
sorting arrays, 51–52 |
System.Data.SqlClient namespace, 315 |
sound |
Stack class |
playing simple beep or system sound, |
System.Collections.Generic namespace, 54 |
275–276 |
Stack collection |
playing sound files, 277–279 |
ToArray method, 52 |
playing WAV files, 276–277 |
Start method |
SoundPlayer class |
HttpListener class, 346 |
Load method, 276 |
Process class, 135–136 |
LoadSync method, 276 |
Thread class, 113, 132 |
Play method, 276 |
starts-with function, 196 |
PlaySync method, 276 |
StartType property |
System.Media namespace, 275–276 |
ServiceInstaller class, 516 |
SPC (Software Publisher Certificate) |
Status property |
creating, 25–27 |
PingReply class, 357 |
SpecialFolders property |
Stop method |
WshShell class, 518–519 |
WebBrowser control, 254 |
Speed property |
stored procedure |
NetworkInterface class, 337 |
executing, 311–315 |
sprite |
using parameters in, 315–318 |
creating moveable sprite, 265–268 |
StoredProcedure value |
SQL command |
CommandType enumeration, 312 |
executing, 311–315 |
storing a connection string securely, 308–311 |
using parameters in, 315–318 |
Stream class |
SQL query |
System.IO namespace, 56, 72, 341, 426, 430 |
processing results with data reader, 318–321 |
StreamingContext class, 459 |
SQL Server |
System.Runtime.Serialization namespace, |
discover all instances on Network, 331–333 |
459 |
performing asynchronous database |
StreamReader class |
operations against, 324–327 |
Read method, 156–157 |
SQL Server query |
ReadLine method, 156–157 |
obtaining XML document from, 321–324 |
ReadToEnd method, 157 |
SqlCeCommand class |
System.IO namespace, 344 |
System.Data.SqlServerCe namespace, 311 |
StreamWriter class |
SqlCeConnection class |
System.IO namespace, 156 |
System.Data.SqlServerCe namespace, 301 |
Write method, 156 |
SqlCeDataReader class |
WriteLine method, 156 |
System.Data.SqlServerCe namespace, 319 |
String class |
SqlCeParameter class |
as connection strings, 307 |
System.Data.SqlServerCe namespace, 315 |
Format method, 484 |
SqlClientFactory class, 330 |
immutability of objects, 32 |
System.Data.SqlClient namespace, 329 |
insecurity of, 432 |
SqlCommand class |
System namespace, 463, 484 |
ExecuteXmlReader method, 321–322 |
string manipulation, 31–33 |
methods, 324 |
String value |
System.Data.SqlClient namespace, 311 |
DbType enumeration, 316 |
SqlConnection class |
StringBuilder class, 211 |
example, 302 |
Capacity property, 32 |
System.Data.SqlClient namespace, 301, 325 |
Length property, 32 |
SqlConnectionStringBuilder class |
MaxCapacity property, 32 |
parsing and constructing SQL Server |
ReverseString method, 32 |
connection strings, 307–308 |
System.Text namespace, 31, 88, 428 |
System.Data.SqlClient namespace, 307 |
ToString method, 31 |

556 ■I N D E X
strings |
Synchronized method |
See also mutable strings |
collection classes in System.Collections, 134 |
creating dates and times from, 47–49 |
SyncRoot property |
fixed-length strings, 445 |
collections in System.Collections.Specialized, |
using alternate character encoding, 33–35 |
134 |
Strong Name tool, 16–17, 21 |
ICollection interface, 134–135 |
-Vr switch, 20 |
System namespace |
-Vu switch, 21 |
Activator class, 90 |
verifying assembly’s strong name, 19 |
AppDomain class, 66, 415 |
strong-named assemblies |
ArgumentException class, 52, 307, 346, 467 |
allowing partially trusted code to use, |
ArgumentNullException class, 88, 487 |
394–396 |
ArgumentOutOfRangeException class, 32, |
delay signing, 20–21 |
487 |
verifying that assembly has not been |
AsyncCallback delegate, 325, 346 |
modified, 19–20 |
Attribute class, 91 |
strong-named key pairs |
AttributeTargets enumeration, 91 |
creating and managing, 16–17 |
AttributeUsageAttribute class, 91 |
strong-names |
BitConverter class, 36, 427 |
giving to assemblies, 17–19 |
CannotUnloadAppDomainException class, |
strongly typed collections |
83 |
using, 54–55 |
Console class, 28, 61, 483 |
StrongName class |
ConsoleColor enumeration, 29 |
System.Security.Policy namespace, 408 |
ConsoleKeyInfo class, 62 |
StrongNameIdentityPermission class, 408 |
Convert class, 38 |
System.Security.Permissions namespace, |
DateTime structure, 31, 47, 109, 144, 468 |
408 |
Enum class, 87 |
StrongNameIdentityPermissionAttribute class, |
Environment class, 10, 499 |
409 |
Environment.SpecialFolder enumeration, |
StructLayoutAttribute class, 444 |
501 |
constructor, 445 |
EnvironmentVariableTarget enumeration, |
System.Runtime.InteropServices namespace, |
503 |
444 |
EventArgs class, 490, 494 |
Subject property |
Exception class, 487 |
MailMessage class, 353 |
FormatException class, 47, 487 |
SubjectEncoding property |
GC class, 480 |
MailMessage class, 353 |
IAsyncResult interface, 324 |
SubKeyCount property |
ICloneable interface, 463 |
RegistryKey class, 509 |
IComparable interface, 51, 467 |
Subtraction (-) operator |
IDisposable interface, 56, 302, 433, 480 |
supported by TimeSpan and DateTime |
IFormatProvider interface, 484 |
structures, 49 |
IFormattable interface, 483 |
Success value |
IntPtr class, 418, 433, 442 |
IPStatus enumeration, 357 |
InvalidCastException class, 86 |
SuccessAudit value |
InvalidOperationException class, 357, 411, |
EventLogEntryType enumeration, 504 |
432, 475 |
Supports method |
MarshalByRef class, 382 |
NetworkInterface class, 337 |
MarshalByRefObject class, 68, 381 |
SupportsMulticast property |
MissingMethodException class, 75 |
NetworkInterface class, 337 |
NonSerializedAttribute class, 458 |
SuppressFinalize method |
Object class, 54, 463 |
GC class, 481 |
ObjectDisposedException class, 481 |
SuspendLayout method |
OperatingSystem class, 500 |
Control class, 215 |
PlatformNotSupportedException class, |
synchronization, 95–96 |
346 |
access to shared data, 128–130 |
Random class, 421 |
execution of multiple threads |
SerializableAttribute class, 72, 458, 488, 491 |
using a Monitor, 115–120 |
String class, 463, 484 |
using a Mutex, 124–126 |
TimeSpan structure, 108, 389 |
using a Semaphore, 126–128 |
Type class, 52, 319 |
using an event, 120–124 |
Version class, 500 |
