//////////// Write data at the specified position of the file
Insert the string "abcd" into the 10th bytes in the test.txt file.
FileStream fs = new FileStream (@ "c: \ test.txt", Append)
Buf = Encoding. ASCII. GetBytes ("abcd ");
FileStream. Seek (10, Begin );
FileStream. Write (buf );
//////////// When calling an external DLL, the system prompts "the interoperability type cannot be embedded"
Right-click the referenced class library and choose Properties.
-- Double-click the embedded interoperability type (change to false ).
//////////// Modify the global character set
<System. web>
<Globalization requestEncoding = "gb2312" responseEncoding = "gb2312" fileEncoding = "gb2312" culture = "zh-CN"/>
</System. web>
//// //. Net3.5. Net4 is deployed on the same website.
Each has a virtual directory to specify the application pool,
The main directory cannot contain web. config.
////////////. Net strong name signature assembly
Project -- Property -- signature -- select as assembly signature -- select strong name key file -- New
Recompile
Mostly used as COM components to interact with other programs
If an assembly with a strong name signature is tampered with, the CLR fails to load the Assembly for integrity verification.
However, strong names can be removed using other tools.
//// //. Net Framework 4.5 native support for zip Compression
The System. IO. Compression. FileSystem assembly of the project must be referenced.
Using System. IO. Compression;
String startPath = @ "c: \ example \ start ";
String zipPath = @ "c: \ example \ result.zip ";
String extractPath = @ "c: \ example \ extract ";
// Compression
ZipFile. CreateFromDirectory (startPath, zipPath );
// Extract
ZipFile. ExtractToDirectory (zipPath, extractPath );
////////////// Program for 32-bit running in 64-bit Systems
Project Properties -- generate -- target platform -- select x86
/// //. Net WebService call url
When the system calls the WebService path, it will be in the dll
After decompiling the dll, you can find
*. In Properties. Settings, there is a DefaultSettingValue on each service string, which is the path we set in Settings.
Change this path: You can directly modify the corresponding value in Web. Config by calling WebService in a Web project.
You can use new Service (). Url in dll to assign values.
/////////////// 64-bit IIS Excel operation
Insufficient DCOM Permissions
Mmc-32
ADD management unit-Component Service
Go to DCOM -- Microsoft Word * or {00020906-0000-0000-C000-000000000046}
Attribute -- Security -- all custom, add all everyone Permissions -- select the interactive user as the ID (if not, enter the super Administrator as the following user)
////////////////. Net escape character string containing escape characters
Regex. Unescape (string)
Input string content (\ is an entity character): "a \ r \ n \ tb"
Return string:"
B"
/////////////// In WinForm, add the Ctrl + A select all shortcut key to the TextBox.
Private void txtStatus_KeyDown (object sender, KeyEventArgs e)
{
If (e. Modifiers = Keys. Control & e. KeyCode = Keys.)
{
(TextBox) sender). SelectAll ();
}
}
//// // C # IIS ManagementException: Access Denied
Principle: The permission for running pages (related to IIS) is lower than the permission for running DLL. It is estimated that Microsoft has designed this vulnerability for hackers. It is okay to obtain this value in Global or httpModules.
You can obtain the CPU memory status in real time and refresh the value every 5 seconds in Global.
////////////////// C # execute the command line program in the command line program and display the output
ProcessStartInfo start = new ProcessStartInfo ("dtexec.exe ");
Start. Arguments = "/F \" "+ AppPath +" \ update data. dtsx \ "/De 1 ";
Start. CreateNoWindow = true; // The doscommand line window is not displayed.
Start. RedirectStandardOutput = true ;//
Start. RedirectStandardInput = true ;//
Start. UseShellExecute = false; // whether to specify the Operating System Shell Process Startup Program
Process p = Process. Start (start );
StreamReader reader = p. StandardOutput; // captures the output stream
String line = reader. ReadLine (); // read a row each time
While (! Reader. EndOfStream)
{
Console. WriteLine (line );
Line = reader. ReadLine ();
}
P. WaitForExit (); // wait for the program to exit after execution
P. Close (); // Close the process
Reader. Close (); // Close the stream
//////////////// // VS. NET compiled DLL, XML annotation (Sumarry annotation) Output
Project Properties -- generate -- select xml document file in output -- generate
////////////// // When an error is reported on the website, the system automatically returns the error message (error.html) to the specified page.
ASP. NET performs the following configuration under web. config on the web layer:
When a page error is reported in the web layer, the error.htm page under the root directory is automatically displayed, prompting users to be very user-friendly.
<System. web>
<CustomErrors mode = "On" defaultRedirect = "~ /Error.htm "> </customErrors>
</System. web>
/// // Download the object
WebClient client = new WebClient ();
Try
{
Client. DownloadFile (uri, savePath );
}
Catch
{
}
//// // Task asynchronous application in RavenDb. Net4
Internal partial class RavenService: ServiceBase {
Private RavenDbServer server;
Private Task startTask;
Public RavenService ()
{
InitializeComponent ();
}
Protected override void OnStart (string [] args)
{
// Start a single thread to start the service
StartTask = Task. Factory. StartNew () =>
{
Try
{
Server = new RavenDbServer (new RavenConfiguration ());
}
Catch (Exception e)
{
EventLog. WriteEntry ("RavenDB service failed to start because of an error" + Environment. NewLine + e, EventLogEntryType. Error );
Stop ();
}
});
// Prompt when wait 20 seconds until startup
If (startTask. Wait (TimeSpan. FromSeconds (20) = false)
{
EventLog. WriteEntry (
"Startup for RavenDB service seems to be taking longer than usual, moving initialization to a background thread ",
EventLogEntryType. Warning );
}
}
Protected override void OnStop ()
{
// Asynchronous waiting for destruction
StartTask. ContinueWith (task =>
{
If (server! = Null)
Server. Dispose ();
Return task;
}). Wait ();
}
}
////////////// Winform to obtain the file path dragged to the control
Set the control's AllowDrop = true
Write code in the DropEnter event:
If (e. Data. GetDataPresent (DataFormats. FileDrop ))
{
String filePath = (System. Array) e. Data. GetData (DataFormats. FileDrop). GetValue (0). ToString ();
}
//// // XMLDocument error: the node to be inserted comes from different document contexts
Use XmlDocument. ImportNode to import the node to the current document.
Xn = xd. ImprotNode (xn );
XnP. AppendChild (xn );
//// // Display the binary value of the registry
String strA = "44,00, 3a, 00,00, 00 ";
String [] arrA = strA. Split (',');
List <byte> listB = new List <byte> ();
For (int I = 0; I <arrA. Length; I + = 2)
{
String strN = arrA;
ListB. Add (byte) Convert. ToInt32 (strN, 16 ));
}
String strResult = Encoding. GetEncoding ("GB2312"). GetString (listB. ToArray ());
/////////////// Byte: convert to a hexadecimal string and fill in two digits
B. ToString ("X2 ")