Hi,
I have a requirement to save the InfoPath data in database. For any error occured while saving the data to database, I wanted to rollback the InfoPath form changes commited to Forms Library.
To achive the above functionality, I implemented following approaches (to achive the above functionality) in the insert & edit mode of the InfoPath form
1. I set the versioning property ON for the Forms Library
2. In the INSERT mode while inserting the data to DB if system encounters error, I programatically tried deleting the newly created .xml file from the SharePoint Forms Liabrary
3. In the EDIT mode when there is any excpetion editing the data in DB, I programatically tried deleting the latest version of .xml file (which had the latest InfoPath form updates that are committed to Forms Library)
In the process of deleting the latest version of .xml files I get following error : Microsoft.SharePoint.SPException: Cannot delete the current version
To delete the latest version file, I have implemented the below logic:
SPSite spSite = new SPSite(spSiteUrl);
SPWeb spWeb = spSite.RootWeb;
SPListItem spForm = FindForm(spWeb, GetFormName(formName)); // .xml file name
if (spForm != null)
{
if (spForm.Versions.Count >= 1)
{
spForm.Versions[0].Delete();
return true;
}
else
{
return false;
}
}
But I am able to successfully able to delete the lower version files but get while deleting the latest version file I get the above error. To avoid the SPException, am I missing some setting in my above code?
Can any body suggest for the best possible solution /approach to achive the above functionality (of rolling back the InfoPath form changes to Forms Library OR transactionalising the InfoPath form & DB data save)?
Regards,
Vipul Mehta