dotnetspider.com Home page     All Communities

Dotnet Experts in India


Set dotnet version for Virtual directory thro Code



My Profile 
  • Sign In
  •  
  • Register

  • Links 
  • Message Center
  •  
  • File Manager
  •  
  • Members
  •  
  • Hall Of Fame
  •  
  • Site Configuration





  • Set dotnet version for Virtual directory thro Code


    Posted Date: 03 Dec 2008      Total Responses: 0

    Posted By: anil_karg       Member Level: Silver     Points: 50


    Here is the function to set asp.net version for a virtual directory.

    Private Sub SetAspNetVersion(ByVal frameworkVersion As String, ByVal IISWeb As String)
    Dim frameworkDirectory As String
    Dim directory__1 As String
    Dim al As System.Collections.ArrayList

    'Execute the following command in the correct .net framework version directory.
    'Aspnet_regiis.exe -s W3SVC/1/ROOT/SampleApp1
    If frameworkVersion <> "v1.1.4322" Then
    al = New System.Collections.ArrayList()
    directory__1 = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory()

    Dim dirPos As Integer = directory__1.Remove(directory__1.Length - 1, 1).LastIndexOf("\")
    frameworkDirectory = directory__1.Remove(dirPos, directory__1.Length - dirPos)
    frameworkDirectory = (frameworkDirectory & "\") + frameworkVersion & "\"

    If Not Directory.Exists(frameworkDirectory) Then
    Throw New Exception("Cannot find framework. Check correct framework is installed")
    End If

    Dim process As New Process()
    process.StartInfo.UseShellExecute = False
    process.StartInfo.RedirectStandardOutput = True
    process.StartInfo.RedirectStandardError = True
    process.StartInfo.FileName = frameworkDirectory & "aspnet_regiis"
    process.StartInfo.Arguments = ("-s " & "W3SVC/1/ROOT/") + IISWeb
    process.Start()
    process.WaitForExit()

    End If
    End Sub

    Here is how u call it
    SetAspNetVersion("2.0.50727", "Woof")

    Where 1st param is the version to set (Check the version u have installed before setting the param) and 2nd param is name of virtual directory.
    Dont forget to include these namespaces!

    Imports System
    Imports System.DirectoryServices
    Imports System.Collections.Generic
    Imports System.Text
    Imports System.IO
    Imports System.Data

    Happy coding..




    Responses


    No responses found. Be the first to respond and make money from revenue sharing program.

    Post Reply
    You must Sign In to post a response.
    Next : Convert C# code to VB.Net and Vice Versa
    Previous : store an image in Sql Server using VB.NEt
    Return to Discussion Forum
    Post New Message
    Category:

    Related Messages