Writing XML file within Loop (c#)
I am trying to write xml files to the client machine in a loop. The first one saves correctly, and then the page stops processing, without errors.
My loop:
//Loop through form fields and call getaudit for every checked value
for(int i = 0; i < Request.Form.Count;i++)
{
if(Request.Form[Request.Form.AllKeys[i]] == "on")
{
//this is a checkbox, parse the string for values
string activityid = Request.Form.AllKeys[i].Substring(0,Request.Form.AllKeys[i].IndexOf("~")).ToString();
string objectid = Request.Form.AllKeys[i].Substring(Request.Form.AllKeys[i].IndexOf("~")+1).ToString();
//call function to write file
SaveAudittoClient(activityid, objectid);
}
}
CODE THAT WRITES XML FILE:
//Return XML for infopath to access
Response.ContentType = "text/xml";
Response.AddHeader("Content-Disposition", "attachment;filename=" + CleanFileName(CRMd.HotelName) + "_" + CRMd.Brand + "_" + DateTime.Now.ToFileTime() + ".xml");
Response.Write(infoPathXmlTemplate.InnerXml);
-----------
I originally had the writing of the file in a separate aspx page, using Server.Execute, but it had the same behavior, only processing the first file in the group.
I've tested with multiple checkboxes checked, and without the function call, the method loops correctly. With the function call to write the file, the method executes correctly only on the first file.
Any suggestions? Thanks in advance for your help!
|