views:

1339

answers:

2

I am creating an installer for a silverlight application and would like to be able to register the .xap extension for IIS automatically. Is there a way to accomplish this without editing the registry? If not, what registry entries to I need to make? Thanks!

+2  A: 
  1. Start->run inetmgr (launch IIS management console)
  2. Click on MIME Types
  3. Click Add.. .xap application/x-silverlight-app
  4. Press OK

or you could save this code to a text file and execute it on the server:

AddMimeType.vbs

Dim VPath
'This changes setting at machine level, you may change it to a different path
VPath = "IIS://localhost/MimeMap"

'Add/Update the type for DLR language extension
UpdateMime ".xap", "application/x-silverlight-app"

'Search for the given extension and update its type
'when not found, add it into the collection
Sub UpdateMime(Extension, NewType)
    Dim LocalMimeMap, MimeMap, MMItem, aMimeMapNew()
    Dim i 
    i = 0
    Const ADS_PROPERTY_CLEAR = 1
    Const ADS_PROPERTY_UPDATE = 2
    Set LocalMimeMap = GetObject(VPath)
    MimeMap = LocalMimeMap.GetEx("MimeMap")
    Dim found
    found = False
    For Each MMItem In MimeMap
      ReDim Preserve aMimeMapNew(i)
      Set aMimeMapNew(i) = CreateObject("MimeMap")
      aMimeMapNew(i).Extension = MMItem.Extension
      If MMItem.Extension = Extension Then
          found = True
          MsgBox("Update type of extension " + MMItem.Extension + " from " +     MMItem.MimeType + " to " + NewType)
          aMimeMapNew(i).MimeType = NewType
      Else
          aMimeMapNew(i).MimeType = MMItem.MimeType
      End If
      i = i + 1
    Next
    If found Then
        LocalMimeMap.PutEx ADS_PROPERTY_UPDATE, "MimeMap", aMimeMapNew
        LocalMimeMap.SetInfo
    Else
        MsgBox("Add new extension " + Extension + " with type " + NewType)
        AddMime Extension, NewType
    End If
End Sub

Sub AddMime(ExtensionToAdd, MimeTypeToAdd)
    Dim LocalMimeMap, MimeMap
    Dim i
    Const ADS_PROPERTY_UPDATE = 2
    Set LocalMimeMap = GetObject(VPath)
    MimeMap = LocalMimeMap.GetEx("MimeMap")
    i = UBound(MimeMap)+1
    Redim Preserve MimeMap(i) 
    Set MimeMap(i) = CreateObject("MimeMap") 
    MimeMap(i).Extension = ExtensionToAdd
    MimeMap(i).MimeType = MimeTypeToAdd
    LocalMimeMap.PutEx ADS_PROPERTY_UPDATE,"MimeMap",MimeMap 
    LocalMimeMap.SetInfo
End Sub
Michael S. Scherotter
A: 

the script doesnt work

maybe the .extension not declared