如何使用c#将文件移动到虚拟目录

时间:2012-08-04 06:06:08

标签: c# iis windows-installer virtual-directory

我以编程方式创建了一个虚拟目录。现在我想将HTML文件上传到创建的虚拟目录。我怎样才能做到这一点?

段:

DirectoryEntry Rootdir =  new DirectoryEntry("IIS://localhost/W3SVC/1/Root");
DirectoryEntry dir= Rootdir .Children.Add("MyDirectory", "IIsWebVirtualDir");
Directory.CreateDirectory(Rootdir .Properties["Path"].Value+"\\MyDirectory");
dir.Properties["Path"].Insert(0, Rootdir .Properties["Path"].Value + "\\MyDirectory");
dir.CommitChanges();
Rootdir .CommitChanges();
dir.close();
Rootdir.close();

1 个答案:

答案 0 :(得分:0)

FileInfo fileInfo = new FileInfo(@"C:\inetpub\wwwroot\iisstart.htm");
File.Copy(fileInfo.FullName, Rootdir.Properties["Path"].Value + "\\MyDirectory" + "\\" + fileInfo.Name);