
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.
Blog about Sharepoint (WSS/MOSS) 2007 & 2010, Web Parts, Workflows, ASP.NET, .NET 3.5



this.EventManager.XmlEvents["/my:myFields/my:Type"].Changed += new XmlChangedEventHandler(TypeChanged);
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();
}

(using Microsoft.SharePoint.Administration;)
string siteName = "http://moss";
SPSite site = .....;
SPWebApplication webApp = site.WebApplication;
System.Collections.ObjectModel.CollectionallModifications= webApp.WebConfigModifications;
AddNewAppSetting(allModifications,"testkey1","testvalue1");
AddNewAppSetting(allModifications,"testkey2","testvalue2");
SPFarm.Local.Services.GetValue().ApplyWebConfigModifications();
------
private void AddNewAppSetting(System.Collections.ObjectModel.CollectionallModifications,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);
}
<pre>
<Where>
<Eq>
<FieldRef Name='Summary'/><Value Type='Text'>jeroen & doreen></Value>
</Eq>
</Where>
<Where>
<Eq>
<FieldRef Name='Summary'/>
<Value Type='Text'> <![CDATA[jeroen & doreen]]> </Value>
</Eq>
</Where>
<script> |

//Get search Schema
ServerContext serverContext = ServerContext.GetContext("SharedServices1");
SearchContext searchContext = SearchContext.GetContext(serverContext);
Schema schema = new Schema(searchContext);
//Get the list of properties (here from a published infoPath Form), you want to use in search
StringCollection infoPathFormProperties = GetData.GetAllInfoPathPublishedFields();
// Create new ManagedProperties
foreach (string infoPathFormProperty in infoPathFormProperties)
{
string managedPropertyName = infoPathFormProperty;
string infoPathFormPropertyPublished = string.Format("ows_{0}", infoPathFormProperty); //infopath published fields will be added as ows_[NAME]
// If you create a prop that already exists, you will get an SqlException (duplicate key),so you need this check
if (!schema.AllManagedProperties.Contains(managedPropertyName))
{
ManagedProperty newManagedProperty = schema.AllManagedProperties.Create(managedPropertyName, ManagedDataType.Text);
// Get the (crawled) property you want to map in the ManagedProperty
CrawledProperty cprop = null;
foreach (CrawledProperty prop in schema.QueryCrawledProperties(infoPathFormPropertyPublished, 1000, Guid.NewGuid(), string.Empty, true))
{
//schema.GetCrawledProperty(Guid.NewGuid(), infoPathFormPropertyPublished, 0); //can't use this, you need also need the Guid and variantType, and you only know the name
//QueryCrawledProperties will be filtered on CONTAINING infoPathFormPropertyPublished value, so extra check if the Name is equal!
if (prop.Name == infoPathFormPropertyPublished)
{
cprop = prop;
break;
}
}
if (cprop != null)
{
// Map the crawled prop to the Managed Prop
MappingCollection mappings = new MappingCollection();
mappings.Add(new Mapping(cprop.Propset, cprop.Name, cprop.VariantType, newManagedProperty.PID));
newManagedProperty.SetMappings(mappings);
// Set Some other properties
newManagedProperty.FullTextQueriable = true;
newManagedProperty.EnabledForScoping = true;
newManagedProperty.Update();
}
else
{
MessageBox.Show(string.Format("Published Infopath field {0} not found",infoPathFormPropertyPublished));
}
}
else
{
MessageBox.Show(infoPathFormProperty +" already exists");
}
}
CAML QUERY
QUERY SHAREPOINT
When you write custom code in Sharepoint webparts, your code will run with your credentials.
Not everybody has Full Control, so when a user has only read rights, the code will throw an access denied error when the code needs access to objects that are not in the scope of the user credentials.... (example: add the username in the ReadBy properties of an item).
What you need is impersonation, run your code with the help of a user who has just enough rights to run it. Sharepoint has a built-in function to accomplish this: SPSecurity.RunWithElevatedPrivileges, it runs with the System Account User.
Some things you should know when using SPSecurity.RunWithElevatedPrivileges:
Code sample:
I run the "Elevated code" when the button btn is clicked in a webpart:
void btn_Click(object sender, EventArgs e)
{
{
SPSecurity.RunWithElevatedPrivileges(TestSec);
}
catch (Exception ex)
{
throw ex;
}
}
public void TestSec()
{
SPSite siteColl = new SPSite(App.SITE_COLLECTION_URL);
SPWeb site = siteColl.AllWebs[App.WEB_NAME];
SPList list = site.Lists["Test"];
SPListItem testItem = list.GetItemById(1);
site.AllowUnsafeUpdates = true;
SPRoleDefinition roleDefinitionContributor = site.RoleDefinitions.GetByType(SPRoleType.Contributor);
SPRoleAssignment roleAssignment = new SPRoleAssignment("DOMAIN\\USERNAME", "", "", "");
roleAssignment.RoleDefinitionBindings.Add(roleDefinitionContributor);
////Check for permission inheritance, and break if necessary
if (!testItem.HasUniqueRoleAssignments)
{
testItem.BreakRoleInheritance(false); //pass true to copy role assignments from parent, false to start from scratch
}
testItem.RoleAssignments.Add(roleAssignment);
testItem.Update();
site.AllowUnsafeUpdates = false;
siteColl.Close();
site.Close();
}
Sources:
More info @ http://www.hanselman.com/blog/Reflector5ReleasedWorldDominationAssured.aspx
Before reading this post:
When initializing a replicator you need to pass initiation data (like the foreach collection data). So if you want to pass a Contact for each replicated activity, you will set the initiationChildData (must implement IList) with Contact objects:
I will use the example when a dataconnection (webservices) in the form gives a time-out.
Preceding:
First keep in mind that we will bind the dataconnection-webservice to its control in code, so you have to deselect - Automatically retrieve data when form is opened (when adding a data-connection in InfoPath). Also don't forget to link the control with the dataconnection in infopath designer
What we gonna do in code:
- Add a handler that will get you into the Initialize methods of the XmlFormView
- Get the right dataconnection, execute it (so it will get the data and bind to the control)
- Add a "try/catch" block around this code
The code:
void viewform_Initialize(object sender, InitializeEventArgs e)
{
try
{
DataConnection dc = _viewform.XmlForm.DataSources["GetGAL"].QueryConnection;
dc.Execute();
}
catch (System.Net.WebException webEx)
{
WarmUpWebService();
ReloadWebPart();
//Log, ...
}
catch (Exception ex)
{
Logger.Log(ex, ...);
}
}
Some other InfoPath blogs:

(go to Kristof his blog for full explanation)