add location elemet to web.config programmatically

  • Thread starter Thread starter Darko Bazulj
  • Start date Start date
D

Darko Bazulj

How to add next to web.config

<location path="9998886">
<system.web>
<compilation
tempDirectory="D:\logs\temporary_asp_net_files\9998886" />
</system.web>
</location>

<location path="444">
<system.web>
<compilation tempDirectory="D:\logs\temporary_asp_net_files\444"
/>
</system.web>
</location>

I can read and modify existing locations but don't know how to add/delete
new locations.

Can someone point me to right direction or give some example.



' Open configuration.
Dim config As Configuration =
WebConfigurationManager.OpenWebConfiguration(Nothing)
Dim value As ConfigurationLocationCollection = config.Locations

Dim myLocation As ConfigurationLocation


For Each myLocation In value


If myLocation.Path = "9998886" Then

Console.WriteLine(myLocation.Path)

Dim myLocationConfiguration As Configuration =
myLocation.OpenConfiguration()
' Get the section related object.

Dim configSection As System.Web.Configuration.CompilationSection =
_CType(myLocationConfiguration.GetSection("system.web/compilation"), _
System.Web.Configuration.CompilationSection)

Console.WriteLine("Location Configuration File Path: {0}",
myLocationConfiguration.FilePath)
' Display TempDirectory property.

Console.WriteLine("TempDirectory: {0}", _
configSection.TempDirectory)

'' Set TempDirectory property.
'configSection.TempDirectory =
"D:\logs\temporary_asp_net_files\novi_temp_folder"

'' Update if not locked.
'If Not configSection.SectionInformation.IsLocked Then
' myLocationConfiguration.Save()
' Console.WriteLine("** Configuration updated.")
'Else
' Console.WriteLine("** Could not update, section is locked.")
'End If
'' Display TempDirectory property.
'Console.WriteLine("TempDirectory: {0}", _
' configSection.TempDirectory)

End If

Next

Console.WriteLine(value.Count)
 
Back
Top