Quantcast
Channel: SharePoint 2010 - Setup, Upgrade, Administration and Operations forum
Viewing all articles
Browse latest Browse all 13778

SPWebConfigModification error “The '[' character, hexadecimal value 0x5B, cannot be included in a name. Line 2, position 2727.”

$
0
0

I am using SPWebConfigModification thorugh webapplication feature everytime it shows error "The '[' character, hexadecimal value 0x5B, cannot be included in a name. Line 2, position 2727." I am very puzzled with this error. I have tried every possible solution given in Google with no help.The code I am using is given below: I am using a feature receiver.

[Guid("c35d2a13-980c-4afb-a832-26d9f7cec85f")]
publicclassWebConfigMod2EventReceiver:SPFeatureReceiver
{
   
// Uncomment the method below to handle the event raised after a feature has been activated.

   
publicoverridevoidFeatureActivated(SPFeatureReceiverProperties properties)
   
{
    
        try
       
{
           
SPSecurity.RunWithElevatedPrivileges(delegate()
           
{
               
SPWebApplication spWebApplication = properties.Feature.ParentasSPWebApplication;
               
Removemodifications(spWebApplication);
               
SPWebConfigModification myModification =newSPWebConfigModification();
                myModification
.Path="configuration";
                myModification
.Name="Location[@name='Test']";
                myModification
.Sequence=0;
                myModification
.Owner="Moumita";
                myModification
.Type=SPWebConfigModification.SPWebConfigModificationType.EnsureSection;
                myModification
.Value="<location path='Test'></location>";
                spWebApplication
.WebConfigModifications.Add(myModification);
                spWebApplication
.Update();
                spWebApplication
.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
           
});
       
}
       
catch(Exception ex)
       
{
           
throw ex;
       
}
   
}


   
// Uncomment the method below to handle the event raised before a feature is deactivated.

   
publicoverridevoidFeatureDeactivating(SPFeatureReceiverProperties properties)
   
{
       
try
       
{
           
SPWebApplication spWebApplication= properties.Feature.ParentasSPWebApplication;
           
Removemodifications(spWebApplication);
            spWebApplication
.Update();
            spWebApplication
.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
       
}
       
catch(Exception ex)
       
{
           
throw ex;
       
}

   
}
   
publicvoidRemovemodifications(SPWebApplication webApp)
   
{
       
try
       
{
           
Collection<SPWebConfigModification> spWebConfigModifications= webApp.WebConfigModifications;
           
SPWebConfigModification spWebConfigModificationToRemove=null;
           
foreach(var spWebConfigModification in spWebConfigModifications)
           
{
               
if(spWebConfigModification.Name=="Location[@name='Test']"&& spWebConfigModification.Path=="configuration")
               
{
                    spWebConfigModificationToRemove
= spWebConfigModification;
                   
break;
               
}
           
}
           
if(spWebConfigModificationToRemove !=null)
           
{
                webApp
.WebConfigModifications.Remove(spWebConfigModificationToRemove);
           
}
       
}
       
catch(Exception ex)
       
{
           
throw ex;
       
}

   
}

Please help me asap.

Thanks,

Mou


Viewing all articles
Browse latest Browse all 13778

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>