locked
InfoPath 2010: Document Sets: How Do You Access the Document Set That Owns a Document from Workflow/InfoPath 2010? RRS feed

  • Question

  • We are building a solution using a Document Set content type. Various documents, of course, can be added to the document set including InfoPath 2010 forms. InfoPath 2010 forms are processed asynchronously by the business, i.e., separate forms can be started by several business units and may be in flight for various periods. We can attach a status field to each form to inidicate if it's complete or not. Certain business processes - that are managed from InfoPath forms - may have a dependency on other InfoPath forms. So, for example, Form B may get started but will be gated until Form A is complete. We would like to represent the status of each form in the Document Set at the level of the Document Set so that you can view the Document Set and see the status of various forms, i.e., business processes, inside each document set and roll all the business process status values up into a status for the document set. There does not, however, appear to be a way to identify the Document Set that owns an InfoPath form from a workflow that is running after the form is submitted or saved. The submitted/saved event, of course, is the point at which the business process status has changed. Nor does there appear to be a way to peruse the list of documents in a Document Set from a workflow which would be a less desirable way to find the status of documents in the Document Set but would still meet our timing requirements. Is there a way to find the Document Set that owns a document, i.e., InfoPath form, in the Document Set from the InfoPath form? That is to say, this is a fairly straight-forward parent/child relationship. I would think the child should be able to identify its parent. Once we've identified the parent, of course, we should be able to access parent columns, i.e., status values of other InfoPath forms in the Document Set, so that business process dependencies can be honored.
    Thursday, July 7, 2011 4:22 PM

Answers

  •  public static bool IsPartOfDocumentSet(string url)
     {
    
          DocumentSet ds = null;
    
          using (SPSite site = new SPSite(url))
          {
            using (SPWeb web = site.OpenWeb())
            {
              object value = web.GetFileOrFolderObject(url);
    
              if(typeof(SPFile).IsAssignableFrom(value.GetType()))
              {
                SPFile file = value as SPFile;
                
                ds = DocumentSet.GetDocumentSet(file.ParentFolder);
                
              }
              else
              {
                if(typeof(SPFolder).IsAssignableFrom(value.GetType()))
                {
                  SPFolder folder = value as SPFolder;
                  ds = DocumentSet.GetDocumentSet(folder);
                }
                else
                  return false;
              }
    
              if (ds != null)
              {
                //ds.Folder.Files
                return ds.ContentTypeTemplate.AllowedContentTypes.Count > 0 ? true : false;
              }
              else
                return false;
    
            }
          }
    }
    


    Through code it is easy to identify a url if it is part of a document set. The example code shows you how to use Microsoft.Office.DocumentManagement.DocumentSet class to determine this. Once you get the document set you can look at all the files within the document set using DocumentSet.Folder.Files.

     


    Blog | SharePoint Field Notes Dev Tool | ClassMaster
    • Marked as answer by Wayne Fan Thursday, July 14, 2011 6:27 AM
    Thursday, July 7, 2011 5:40 PM

All replies

  •  public static bool IsPartOfDocumentSet(string url)
     {
    
          DocumentSet ds = null;
    
          using (SPSite site = new SPSite(url))
          {
            using (SPWeb web = site.OpenWeb())
            {
              object value = web.GetFileOrFolderObject(url);
    
              if(typeof(SPFile).IsAssignableFrom(value.GetType()))
              {
                SPFile file = value as SPFile;
                
                ds = DocumentSet.GetDocumentSet(file.ParentFolder);
                
              }
              else
              {
                if(typeof(SPFolder).IsAssignableFrom(value.GetType()))
                {
                  SPFolder folder = value as SPFolder;
                  ds = DocumentSet.GetDocumentSet(folder);
                }
                else
                  return false;
              }
    
              if (ds != null)
              {
                //ds.Folder.Files
                return ds.ContentTypeTemplate.AllowedContentTypes.Count > 0 ? true : false;
              }
              else
                return false;
    
            }
          }
    }
    


    Through code it is easy to identify a url if it is part of a document set. The example code shows you how to use Microsoft.Office.DocumentManagement.DocumentSet class to determine this. Once you get the document set you can look at all the files within the document set using DocumentSet.Folder.Files.

     


    Blog | SharePoint Field Notes Dev Tool | ClassMaster
    • Marked as answer by Wayne Fan Thursday, July 14, 2011 6:27 AM
    Thursday, July 7, 2011 5:40 PM
  • That's very good. Thank you. Is there a way to do it without code? We're having issues getting Sandbox solutions approved by the organization.
    Thursday, July 7, 2011 6:19 PM
  • Hi Donald,

     

    Agree with Steve. as i know, there is no without code solution.

    Thursday, July 14, 2011 6:28 AM