C#获取当前路径的方法
//获取包含清单的已加载文件的路径或 UNC 位置。
public static string sApplicationPath = Assembly.GetExecutingAssembly ( ).Location;
//result: X:\xxx\xxx\xxx.dll (.dll文件所在的目录+.dll文件名)
//获取当前进程的完整路径,包含文件名(进程名)。
string str = this.GetType ( ).Assembly.Location;
//result: X:\xxx\xxx\xxx.exe (.exe文件所在的目录+.exe文件名)
//获取新的 Process 组件并将其与当前活动的进程关联的主模块的完整路径,包含文件名(进程名)。
string str = System.Diagnostics.Process.GetCurrentProcess ( ).MainModule.FileName;
//result: X:\xxx\xxx\xxx.exe (.exe文件所在的目录+.exe文件名)
//获取和设置当前目录(即该进程从中启动的目录)的完全限定路径。
string str = System.Environment.CurrentDirectory;
//result: X:\xxx\xxx (.exe文件所在的目录)
//获取当前 Thread 的当前应用程序域的基目录,它由程序集冲突解决程序用来探测程序集。
string str = System.AppDomain.CurrentDomain.BaseDirectory;
//result: X:\xxx\xxx\ (.exe文件所在的目录+"\")
//获取和设置包含该应用程序的目录的名称。
string str = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
//result: X:\xxx\xxx\ (.exe文件所在的目录+"\")
//获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称。
string str = System.Windows.Forms.Application.StartupPath;
//result: X:\xxx\xxx (.exe文件所在的目录)
//获取启动了应用程序的可执行文件的路径,包括可执行文件的名称。
string str = System.Windows.Forms.Application.ExecutablePath;
//result: X:\xxx\xxx\xxx.exe (.exe文件所在的目录+.exe文件名)
//获取应用程序的当前工作目录(不可靠)。
string str = System.IO.Directory.GetCurrentDirectory ( );
//result: X:\xxx\xxx (.exe文件所在的目录)
//在系统服务中最好用这个方式去取路径
string stmp = Assembly.GetExecutingAssembly ( ).Location;
stmp = stmp.Substring ( 0 , stmp.LastIndexOf ( '\\' ) );//删除文件名
if ( pathType == 1 )
return stmp + @"\inputLog.xml";
else if ( pathType == 2 )
return stmp + @"\MiddleDB.xml";
else
return stmp + @"\AppNo.xml";
using System.IO;
string path = "d:asdfasdf.bmp";
string fileNam
相关文档:
1、引用的空间:
using System.DirectoryServices;
using System.ServiceProcess;
2、调用
private void button1_Click(object sender, EventArgs e)
{
String webSiteName = "默认网站";
String pathToRoot = @"C:\Inetpub\wwwroot";
CreateWebSite(webSit ......
1 JavaScript发送邮件
<script language="javascript">
function SendMail() {
document.location = "mailto:seat@wicresoft.com;?subject=Feedback";
&n ......
冒泡排序
using System;
class Program
{
public static void Main()
{
int[] a = new int[10];
Random rand = new Random();
for (int i = 0; i < 10; i++)
{
a[i] = rand.Next(10);//生成随机数给数组赋值
}
for (int i = 0; i < ......
public void ExportControl(System.Web.UI.Control source, string DocumentType, string filename)
{
//设置Http的头信息,编码格式
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearContent();
......