好文暫存:C#綜合揭祕—通過修改登錄檔建立Windows自定義協議
原文(簡體):C#综合揭秘——通过修改注册表建立Windows自定义协议
Robert 發表在 痞客邦 留言(0) 人氣(80)
在安裝程式中,有時會遇到它的設計是:
移除的檔案 若所在的資料夾 有其他檔案或資料夾,就只把安裝的檔案刪除,仍留下其他(可能是使用者自己放進去)的檔案/資料夾。
以下是用程式實作的範例:
using System.IO;
// ...
private void DeleteAFile( string fileNamePath )
{
if ( File.Exists( fileNamePath ) )
File.Delete( fileNamePath );
string dirName = Path.GetDirectoryName( fileNamePath );
DirectoryInfo di = null ;
if ( Directory.Exists( dirName ) )
di = new DirectoryInfo( dirName );
while ( di != null && di.Parent != null )
{
if ( di.GetFiles().Length == 0
&& di.GetDirectories().Length == 0 )
{
di.Delete();
}
di = di.Parent;
}
} // DeleteAFile()
Robert 發表在 痞客邦 留言(0) 人氣(183)
public static bool IsConnectingServer()
{
string serverAddress = Properties.Settings.Default.ServerAddress;
try
{
HttpWebRequest request = (HttpWebRequest) WebRequest.Create( serverAddress );
request.Method = "HEAD";
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
return response.StatusCode == HttpStatusCode.OK;
} catch ( Exception )
{
return false;
}
}
Robert 發表在 痞客邦 留言(0) 人氣(317)
舉例:
using System;
using Microsoft.Win32;
// ...
string keyName = @"HKEY_CURRENT_USER\Software\Microsoft\..." // 相當於目錄.
string manifestValue = (string) Microsoft.Win32.Registry.GetValue( keyName, "Manifest", null ); // 相當於檔案'Manifest'.
Robert 發表在 痞客邦 留言(0) 人氣(96)
目前知道的有:
System.IO.StreamWriter
System.IO.File.WriteAllLines
System.IO.File.WriteAllText
System.IO.File.CreateText
Robert 發表在 痞客邦 留言(0) 人氣(16,569)
後來才知道,不存在的路徑+檔案,是無法一次建立的。(目前所知)
Robert 發表在 痞客邦 留言(0) 人氣(4,739)
string path = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)).FullName;
if ( Environment.OSVersion.Version.Major >= 6 ) { // 判斷是不是Vista以上.
path = Directory.GetParent(path).ToString();
}
Robert 發表在 痞客邦 留言(0) 人氣(471)
原來這麼簡單...
Process.Start(@"http://www.google.com");
Robert 發表在 痞客邦 留言(0) 人氣(537)
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
//This line is so you only do the event once
if (e.Url != webBrowser1.Url)
return;
//do you actual code
}
Robert 發表在 痞客邦 留言(0) 人氣(96)
Uri uriResult;
bool result = Uri.TryCreate(uriName, UriKind.Absolute, out uriResult)
&& (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
參考:How to check whether a string is a valid HTTP URL?
Robert 發表在 痞客邦 留言(0) 人氣(872)