I found a solution that works for my needs. This is in C# 3.5:
I created a gridview that lists all of the employees.
In the gridview is a button, that fires the rowcommand:
protected void grdEmployees_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Sort" || e.CommandName == "Page") //if you are sorting or paging, then ignore the call in this method.
return;
//retrieve some of the data from the selected row
GridViewRow gridViewRow = grdEmployees.Rows[(Convert.ToInt32(e.CommandArgument))];
string firstName = gridViewRow.Cells[1].Text;
string lastName = gridViewRow.Cells[2].Text;
string jobTitle = gridViewRow.Cells[3].Text;
//open up the infopath form
var xmlDocument = new XmlDocument {PreserveWhitespace = true}; //this is important, you need to preserve the white space of the original infopath form or else the xmldocument will add whitespace and corrupt the file
xmlDocument.Load(@"C:\InfoPathForm.xml");
var xmlNamespaceManager = new XmlNamespaceManager(xmlDocument.NameTable);
xmlNamespaceManager.AddNamespace("my", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-06-24T18:21:03"); //add the prefix for the "my:" namespace
//set values
xmlDocument.SelectSingleNode("/my:myFields/my:SubjectName", xmlNamespaceManager).InnerText = firstName + " " + lastName; //pre-populate some values from the grid into the form
string fileName = firstName + " " + lastName;
fileName = fileName.Replace(" ", "_") + ".xml";
//set the response
var stringBuilder = new StringBuilder();
var xmlDeclaration = (XmlDeclaration) xmlDocument.FirstChild;
xmlDeclaration.Encoding = "UTF-8"; //this is important, make sure that the encoding is UTF8
xmlDocument.Save(new StringWriter(stringBuilder));
Response.ClearHeaders();
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename="+fileName); //this line will force the user to save the file (instead of saving it on the browser)
Response.ContentType = "application/xml";
Response.ContentEncoding = Encoding.UTF8;
//prep anything that infopath will have problems parsing
string xmlFile = stringBuilder.ToString();
xmlFile = xmlFile.Replace("encoding=\"utf-16\"?>", "encoding=\"utf-8\"?>");//this line is important, if you dont specify UTF8 encoding infopath will not open the document
//deliver the file
Response.Write(xmlFile);
Response.End();
}