maandag, augustus 27, 2007

MCTS for .NET 2.0 Web applications (Exam 070-528)


Just like my colleague MaBal did, I passed the Microsoft.NET Framework 2.0 - Web-based Client Development (Exam 070-528) exam!

Now I can call myself: Microsoft Certified Technology Specialist for .NET framework 2.0 Web applications.

zondag, augustus 19, 2007

Query DataConnection in Infopath Web-enabled Form when selecting value of dropdownlost (with Managed Code)

You don't always need to load your dataconnection before the form is loaded (performance reasons), sometimes you want to load a different dataconnection when a certain value is selected. I use the example of a dropdownlist, and every value of the dropdownlist will load an other dataconnection into another dropdownlist.



Add the 2 dropdownlists, the second dropdownlist must have a connection with a datasource (I use an embedded Xml file dc.xml). When creating this dataconnection, please deselect the setting "Automatically retrieve dat when form is opened".




What you will need after you created the controls in infopath, open VSTA (alt+shift+F12). Add following code fragment into the InternalStartup method:

this.EventManager.XmlEvents["/my:myFields/my:Type"].Changed += new XmlChangedEventHandler(TypeChanged);

You also need to add the TypeChanged methods:

void TypeChanged(object sender,XmlEventArgs e)
{
string type = e.NewValue; //the selected value of the type dropdownlist

//I just added one dataconnection called dc (value when you select POST)
//You need to put here code (switch) for all the values in the type ddl
DataSource ds = this.DataSources[type];
DataConnection dc = ds.QueryConnection;

dc.Execute();
}


When you use the Execute method of a dataconnection, you must change following setting (it is like the ASP.NET AutoPostBack setting), otherwise your dataconnection will not be loaded!! (when you just changed a value of another field, you don't need to change this setting).




Change the standard option (postback settings): "Only when necessary for correct rendering of the form (recommended)" to "Always"


Remarks:
When you use Mananged Code in web-enabled form, uou must publish it as an administrator approved template (check out blogpost http://spsfactory.blogspot.com/2007/01/walkthrough-publishing-administrator.html )

maandag, augustus 13, 2007

Adding AppSettings to a Sharepoint Web Application Web.Config

I use this code to add key/values to the web.config during installation of features


(using Microsoft.SharePoint.Administration;)

string siteName = "http://moss";
SPSite site = .....;
SPWebApplication webApp = site.WebApplication;
System.Collections.ObjectModel.Collection allModifications= webApp.WebConfigModifications;

AddNewAppSetting(allModifications,"testkey1","testvalue1");
AddNewAppSetting(allModifications,"testkey2","testvalue2");

SPFarm.Local.Services.GetValue().ApplyWebConfigModifications();

------

private void AddNewAppSetting(System.Collections.ObjectModel.Collection allModifications,string name, string value)
{
SPWebConfigModification modification = new SPWebConfigModification(string.Format
("add[@key='{0}']", name), "/configuration/appSettings");

modification.Type =
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
modification.Value = string.Format(CultureInfo.InvariantCulture,string.Format
("",name,value) );

if (allModifications.Contains(modification))
{
allModifications.Remove(modification);
}

allModifications.Add(modification);

}


Sources: