I am building a custom webpart. I have also created some generic config class where I get the webPart provisioning settings by current webTemplate internal name. I only need to know how to get the seperated attributes from my string array?

See example of code below:

string[] webTemplateSettings = new string[] { "template:SPSPERS#2,pageUrl:Social/Sites.aspx,webPartZone:LeftZone,title:Site Lidmaatschap", "template:SITEDEFINITIONTEAM#0,pageUrl:Pages/Default.aspx,webPartZone:LeftZone,title:Site Lidmaatschap" };

                        string currentWebTemplateInternalName = GetCurrentWebTemplate(); // for example: SITEDEFINITIONTEAM#0

                        foreach (string webTemplateSetting in webTemplateSettings)
                            // Get settings for current webTemplate
                            if (webTemplateSetting.StartsWith(string.Format("template:{0}", currentWebTemplate)))
                                // split settings
                                string[] webTemplateDetailSettings = webTemplateSetting.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                                string pageUrl = ?
                                string webPartZone = ?
                                string title = ?

                                // do something

You can read it from array using array index

string pageUrl = webTemplateDetailSettings[1];
string webPartZone = webTemplateDetailSettings[2];
string title = webTemplateDetailSettings[3];
|improve this answer|||||
  • isnt there another way to do this without having 2 arrays and looping into the first array? – Ola Apr 30 '15 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.