WinFrom

1.取得和設置當前目錄(即該進程從中啟動的目錄)的完全限定路徑。

02.string str = System.Environment.CurrentDirectory;
03.結果: C:\xxx\xxx
04. 
05.2.取得啟動了應用程序的可執行文件的路徑,不包括可執行文件的名稱。
06.string str = System.Windows.Forms.Application.StartupPath;
07.結果: C:\xxx\xxx
08. 
09.3.取得應用程序的當前工作目錄。
10.string str = System.IO.Directory.GetCurrentDirectory();
11.結果: C:\xxx\xxx
12. 
13.4.取得當前 Thread 的當前應用程序域的基目錄,它由程序集衝突解決程序用來探測程序集。
14.string str = System.AppDomain.CurrentDomain.BaseDirectory;
15.結果: C:\xxx\xxx\
16. 
17.5.取得和設置包含該應用程序的目錄的名稱。
18.string str = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
19.結果: C:\xxx\xxx\
20. 
21.6.取得啟動了應用程序的可執行文件的路徑,包括可執行文件的名稱。
22.string str = System.Windows.Forms.Application.ExecutablePath;
23.結果: C:\xxx\xxx\xxx.exe
24. 
25.7.取得當前執行的exe的文件名。
26.string str = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
27.結果: C:\xxx\xxx\xxx.exe
28. 
29.8.取得當前進程的完整路徑,包含文件名。
30.string str = this.GetType().Assembly.Location;
31.結果: C:\xxx\xxx\xxx.exe
 
 
WebForm

string FilePath = @"D:\test\test.rar";
02.string FilePath1 = @"D:\";
03.string FilePath2 = @"test\test.rar";
04.Response.Write("範例文件:" + FilePath);
05.Response.Write(@"變更副檔名Ans:Ans:D:\test\test.dat");
06.Response.Write(System.IO.Path.ChangeExtension(FilePath, "dat"));
07. 
08. 
09.Response.Write(@"取得檔案路徑Ans:D:\test");
10.Response.Write(System.IO.Path.GetDirectoryName(FilePath));
11. 
12. 
13.Response.Write(@"取得副檔名Ans:.rar");
14.Response.Write(System.IO.Path.GetExtension(FilePath));
15. 
16. 
17.Response.Write(@"取得檔案名稱包含副檔名Ans:test.rar");
18.Response.Write(System.IO.Path.GetFileName(FilePath));
19. 
20. 
21.Response.Write(@"取得檔案名稱不包含副檔名Ans:test");
22.Response.Write(System.IO.Path.GetFileNameWithoutExtension(FilePath));
23. 
24. 
25.Response.Write(@"回傳最上層實體路徑Ans:D:\");
26.Response.Write(System.IO.Path.GetPathRoot(FilePath));
27. 
28. 
29.Response.Write(@"建立隨機檔Ans:mvho5ulp.wrn");
30.Response.Write(System.IO.Path.GetRandomFileName());
31. 
32. 
33.Response.Write(@"建立暫存檔並回傳整路徑Ans:C:\Documents and Settings\Gavin\Local Settings\Temp\tmp6B.tmp");
34.Response.Write(System.IO.Path.GetTempFileName());
35. 
36. 
37.Response.Write(@"系統暫存檔路徑Ans:C:\Documents and Settings\Gavin\Local Settings\Temp\");
38.Response.Write(System.IO.Path.GetTempPath());
39. 
40. 
41.Response.Write(@"是否包含副檔名Ans:True");
42.Response.Write(System.IO.Path.HasExtension(FilePath));
43. 
44. 
45.Response.Write(@"絕對路徑還是相對路徑Ans:True");
46.Response.Write(System.IO.Path.IsPathRooted(FilePath));
47. 
48. 
49.Response.Write(@"取得完整路徑檔名Ans:D:\test\test.rar");
50.Response.Write(System.IO.Path.GetFullPath(FilePath));
51. 
52. 
53.Response.Write(@"將二個路徑合併Ans:D:\test\test.rar");
54.Response.Write(System.IO.Path.Combine(FilePath1, FilePath2));
WebForm2
Response.Write(Request.ApplicationPath);
03.Response.Write(@"Ans: /Web ");
04. 
05.Response.Write(Request.PhysicalPath);
06.Response.Write(@"Ans: D:\Practice\GavinWebSite\Web\DemoRequest.aspx");
07. 
08.Response.Write(Request.PhysicalApplicationPath);
09.Response.Write(@"Ans: D:\Practice\GavinWebSite\Web\");
10. 
11.Response.Write(Request.CurrentExecutionFilePath);
12.Response.Write(@"Ans: /Web/DemoRequest.aspx");
13. 
14.Response.Write(Request.FilePath);
15.Response.Write(@"Ans: /Web/DemoRequest.aspx");
16. 
17.Response.Write(Request.Path);
18.Response.Write(@"Ans: /Web/DemoRequest.aspx");
19. 
20.Response.Write(Request.RawUrl);
21.Response.Write(@"Ans: /Web/DemoRequest.aspx?qy=1");
22. 
23.Response.Write(Request.Url.AbsolutePath);
24.Response.Write(@"Ans: /Web/DemoRequest.aspx");
25. 
26.Response.Write(Request.Url.AbsoluteUri);
27.Response.Write(@"Ans: http://localhost:6101/Web/DemoRequest.aspx?qy=1");
28. 
29.Response.Write(Request.Url.Scheme);
30.Response.Write(@"Ans: http");
31. 
32.Response.Write(Request.Url.Host);
33.Response.Write(@"Ans: localhost");
34. 
35.Response.Write(Request.Url.Port);
36.Response.Write(@"Ans: 6101");
37. 
38.Response.Write(Request.Url.Authority);
39.Response.Write(@"Ans: localhost:6101");
40. 
41.Response.Write(Request.Url.LocalPath);
42.Response.Write(@"Ans: /Web/DemoRequest.aspx");
43. 
44.Response.Write(Request.PathInfo);
45.Response.Write(@"Ans: /info");
46. 
47.Response.Write(Request.Url.PathAndQuery);
48.Response.Write(@"Ans: /Web/DemoRequest.aspx/info?qy=1");
49. 
50.Response.Write(Request.Url.Query);
51.Response.Write(@"Ans: ?qy=1");
52. 
53.Response.Write(Request.Url.Fragment);
54.Response.Write(@"Ans: 空的因為沒有逸出");   
55. 
56.string[] segments = Request.Url.Segments;
57.foreach (string in segments)
58.{
59.Response.Write(s + "<br>");
60.}
61.Response.Write(@"Ans: / ");
62.Response.Write(@"Ans: Web/ ");
63.Response.Write(@"Ans: DemoRequest.aspx/ ");
64.Response.Write(@"Ans: info ");

arrow
arrow
    全站熱搜

    丁滿 發表在 痞客邦 留言(0) 人氣()