add location elemet to web.config programmatically

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top