PDA

View Full Version : آموزش: 6 راه برای بدست آوردن دایرکتوری جاری (انگلیسی)



اسماعیل ابراهیمی
جمعه 05 خرداد 1391, 00:55 صبح
6 ways to get the current directory in C# (http://www.yetanotherchris.me/home/2010/8/17/6-ways-to-get-the-current-directory-in-c.html)



AppDomain.CurrentDomain.BaseDirectory

This is the best option all round. It will give you the base directory for class libraries, including those in ASP.NET applications.
Directory.GetCurrentDirectory()

This does an interop call using the winapi GetCurrentDirectory call inside kernel32.dll, which means the launching process' folder will often be returned. Also as the MSDN documents say, it's not guaranteed to work on mobile devices.
Environment.CurrentDirectory

This simply calls Directory.GetCurrentDirectory()
Assembly.Location

This would be called using
this.GetType().Assembly.Location


This returns the full path to the calling assembly, including the assembly name itself. If you are calling a separate class library, then its base directory will be returned, such "C:\myassembly.dll" - depending obviously on which Assembly instance is being used.
Application.StartupPath

This is inside the System.Windows.Forms namespace, so is typically used in window forms application only.
Application.ExecutablePath

The same as Application.StartupPath, however this also includes the application name, such as "myapp.exe"

clement
سه شنبه 21 آذر 1391, 10:13 صبح
من همه این توابع را تست کردم اما هیچ کدام جواب ندادند اگه کسی می تواند کمک کند ممنون می شم " توی asp.net با C# می خواهم محل فایل های برنامه را پیدا کنم

Y_Safaiee
سه شنبه 21 آذر 1391, 10:33 صبح
من همه این توابع را تست کردم اما هیچ کدام جواب ندادند اگه کسی می تواند کمک کند ممنون می شم " توی asp.net با C#‎ می خواهم محل فایل های برنامه را پیدا کنم
سلام دوست من

اگه اشتباه نکنم تو Asp.net تابعی به نام MapPath هست که همیشه به مکان سایت اشاره میکنه,یعنی مثلا مینویسی MapPath("\1.jpg") در اصل بهش میگی عکس کنار سایت .

مثلا این دستور مسیر جایی که سایت داره اجرا میشه رو بر میگردونه :


Label1.Text=MapPath("").ToString();


موفق باشی
بایت بایت