Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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;
        }
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

piece of cake at the end.

if(!targetFoolder.Exists
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.