How to check if document set exists before importing
-
09-12-2019 - |
Question
I have the following document set extension method, I need that it doesnt try to copy if the document set already exist but dont know how.
public static DocumentSet CopyTo(this DocumentSet documentSet, SPFolder targetFolder, SPContentTypeId targetContentTypeId)
{
Logger.LogDebug("DocumentSetExtensions", "CopyTo(this DocumentSet documentSet, SPFolder targetFolder, SPContentTypeId targetContentTypeId)", "BEGIN");
if (targetFolder == null)
throw new ArgumentNullException("SPFolder targetFolder");
if (targetContentTypeId == null)
throw new ArgumentNullException("SPContentTypeId targetContentTypeId");
DocumentSet newDocumentSet = null;
try
{
using (MemoryStream ms = new MemoryStream())
{
// Export the document set to memory
documentSet.Export(ms);
// Store the current metadata
Hashtable properties = documentSet.Item.Properties;
// Import the document set from memory into the target library
newDocumentSet = DocumentSet.Import(ms, documentSet.Folder.Name, targetFolder, targetContentTypeId, properties, documentSet.ParentList.ParentWeb.CurrentUser);
}
}
catch (Exception ex)
{
Logger.LogError("DocumentSetExtensions", "CopyTo(this DocumentSet documentSet, SPFolder targetFolder, SPContentTypeId targetContentTypeId)", ex);
throw;
}
Logger.LogDebug("DocumentSetExtensions", "CopyTo(this DocumentSet documentSet, SPFolder targetFolder, SPContentTypeId targetContentTypeId)", "END");
return newDocumentSet;
}
Solution
piece of cake at the end.
if(!targetFoolder.Exists
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange