2008-11-19 30 views
4

...或者我堅持自己的「XML斬波」功能。我想創建一個小型tasktray應用程序,以便我可以快速地將虛擬目錄重新指向我的硬盤上的多個文件夾中的一個。是否有.NET庫或API與IIS元數據庫交互/編輯?

一點背景:

我有我的開發機器上我們的代碼庫的3個不同的SVN分支。

Current Production Branch (C:\Projects\....\branches\Prod\) 
Next Release Canidate Branch (C:\Projects\....\branches\RCX\) 
Trunk      (C:\Projects\....\trunk\) 

我們的應用程序與我已經安裝在

http://localhost/cms/ 

爲了工作我們的應用程序必須住在同一個根目錄下的第三方CMS集成。所以:

http://localhost/app/ 

根據分支我的工作,我重新指向/app/目錄通過進入IIS管理器上面列出的3條路徑之一。只是覺得有一個快速應用程序爲我做這件事會很方便。

回答

3

好吧......這不是一個托盤應用程序,但你可以在命令行中運行它。只需根據需要更改物理路徑:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.DirectoryServices; 

namespace Swapper 
{ 
    class Program 
    { 
    static void Main(string[] args) 
    { 
     using (DirectoryEntry appRoot = 
       new DirectoryEntry("IIS://Localhost/W3SVC/1/root/app")) 
     { 
     switch (args[0].ToLower()) 
     { 
      case "prod": 
      appRoot.Properties["Path"].Value = @"e:\app\prod"; 
      appRoot.CommitChanges(); 
      break; 

      case "rcx": 
      appRoot.Properties["Path"].Value = @"e:\app\rcx"; 
      appRoot.CommitChanges(); 
      break; 

      case "trunk": 
      appRoot.Properties["Path"].Value = @"e:\app\trunk"; 
      appRoot.CommitChanges(); 
      break; 

      default: 
      Console.WriteLine("Don't know"); 
      break; 
     } 
     } 
    } 
    } 
} 

然後運行在:

C:\>swapper prod 
C:\>swapper rcx 

+0

榮譽凱文, 應該很容易把這個變成一個我已經擁有的小任務托盤應用程序。非常感激。 – 2008-11-19 12:25:22

1

我沒有使用這個我的自我,所以我不是100%肯定它會解決你的問題。但是請看看.NET中的System.DirectoryServices。它可以訪問IIS。

MSDN help for DirectoryServices