PDA

View Full Version : ایجاد یک Virtual Directory در RunTime



gh_fereydonpoor
شنبه 23 اسفند 1382, 21:07 عصر
سلام به همه دوستان
آقا چطوری میشه یه چیزی شبیه Host Controler نوشت.یعنی به امکانات IIS در زمان اجرا دسترسی پیدا کرد
مرسی ممنون
یا علی
----------------------------------------------
دوست عزیز لطفا در انتخاب عنوان دقت بیشتری کنید
با تشکر - مهدوی

Mahdavi
شنبه 23 اسفند 1382, 22:36 عصر
دوست عزیز واسه ساختن virtual Directory و FTP می تونی از کد زیر استفاده کنی :

private void button1_Click(object sender, System.EventArgs e)
{
string strSchema= "";
string strRootSubPath = "";
if (radioButton1.Checked)
{
strSchema = "IIsWebVirtualDir";
strRootSubPath = "/W3SVC/1/Root";
}
if (radioButton2.Checked)
{
strSchema = "IIsFtpVirtualDir";
strRootSubPath = "/MSFTPSVC/1/Root";
}
if (strSchema == "")
{
strSchema = "IIsWebVirtualDir";
strRootSubPath = "/W3SVC/1/Root";
}
DirectoryEntry deRoot= new DirectoryEntry("IIS://" + txtServer.Text + strRootSubPath);

try
{
deRoot.RefreshCache();
DirectoryEntry deNewVDir = deRoot.Children.Add(txtVDirName.Text,strSchema);

deNewVDir.Properties["Path"].Insert(0,txtVDir.Text);
deNewVDir.CommitChanges();
deRoot.CommitChanges();

// Create a Application
if (strSchema == "IIsWebVirtualDir")
deNewVDir.Invoke("AppCreate",true);

// Save Changes
deNewVDir.CommitChanges();
deRoot.CommitChanges();
deNewVDir.Close();
deRoot.Close();
lblStatus.Text = "Virtual Directory " + txtVDirName.Text + "(" + txtVDir.Text + ") has been created";

}
catch (Exception ex)
{
lblStatus.Text = "Error: " + ex.Message;
}
}


http://www.c-sharpcorner.com/Code/2002/July/CreateVirtDir1.gif
اما Host Controler فقط همین دو مورد نیست . می بایست مدیریت فایل و .... هم داشته باشید. برای نمونه Asp می تونی یه سری به آدرس http://www.inspediumsoft.com/downloads/ بزنی
موفق باشید[/img]