I am stuck with a serious issue when an item is getting added template url is changing to the spItem["TemplateUrl"] = "~sitecollection/FormServerTemplates/" + str[str.Length - 1].ToString()
Same thing when updated it is throwing an exception There is no file with URL 'Testing/Form7aabcddaa.xml' in this Web.
I was updating Form7aabcddaa.xml to form7a but i am getting an exception on modified item which is Form7aabcddaa.xml..Below is the entire code..Please help in fixing this issue..
public override void ItemAdded(SPItemEventProperties properties){
try
{
SPListItem spItem = properties.ListItem;
SPList doclib = spItem.ParentList as SPDocumentLibrary;
SPWeb oWebURL = doclib.ParentWeb;
// SPDocumentLibrary doclib = (SPDocumentLibrary)list;
oWebURL.AllowUnsafeUpdates = true;
SPFieldCollection spFields = spItem.Fields;
foreach (SPField spField in spFields) //loop through fields resetting them
{
if (spField.Type != SPFieldType.Computed &&
spField.Type != SPFieldType.Invalid && !spField.ReadOnlyField)
{
try
{
spItem[spField.InternalName] = spItem[spField.InternalName];
}
catch (Exception e)
{
throw e;
}
}
SPContentType spContentType = doclib.ContentTypes[(SPContentTypeId)spItem["ContentTypeId"]];
//try to update the item with the content type's template url which is the updated one
if (spContentType != null)
{
string strTemplateLink = spItem["TemplateUrl"].ToString();
string[] str = strTemplateLink.Split('/');
if (strTemplateLink.Contains("http") || strTemplateLink.Contains("https"))
{
spItem["TemplateUrl"] = "~sitecollection/FormServerTemplates/" + str[str.Length - 1].ToString();
}
}
spItem.SystemUpdate(false);
}
oWebURL.Update();
oWebURL.AllowUnsafeUpdates = false;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// An item was updated.
/// </summary>
public override void ItemUpdated(SPItemEventProperties properties)
{
try
{
SPListItem spItem = properties.ListItem;
SPList doclib = spItem.ParentList as SPDocumentLibrary;
SPWeb oWebURL = doclib.ParentWeb;
// SPDocumentLibrary doclib = (SPDocumentLibrary)list;
oWebURL.AllowUnsafeUpdates = true;
SPFieldCollection spFields = spItem.Fields;
foreach (SPField spField in spFields) //loop through fields resetting them
{
if (spField.Type != SPFieldType.Computed &&
spField.Type != SPFieldType.Invalid && !spField.ReadOnlyField)
{
try
{
spItem[spField.InternalName] = spItem[spField.InternalName];
}
catch (Exception e)
{
throw e;
}
}
SPContentType spContentType = doclib.ContentTypes[(SPContentTypeId)spItem["ContentTypeId"]];
//try to update the item with the content type's template url which is the updated one
if (spContentType != null)
{
string strTemplateLink = spItem["TemplateUrl"].ToString();
string[] str = strTemplateLink.Split('/');
if (strTemplateLink.Contains("http") || strTemplateLink.Contains("https"))
{
spItem["TemplateUrl"] = "~sitecollection/FormServerTemplates/" + str[str.Length - 1].ToString();
}
}
spItem.SystemUpdate(false);
}
oWebURL.Update();
oWebURL.AllowUnsafeUpdates = false;
}
catch (Exception ex)
{
throw ex;
}
}