SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an InfoPath form with a connection to a document library that holds document sets. I have the ID of the specific document set. How can I make the InfoPath form display Links to the documents of that Document set?

share|improve this question


Mano Mangaldas

This doesnt create the link in InfoPath, but since you haven't recieved any answers maybe this will give you or someone else a jumping off point.

public static SPFile CreateDocumentLink(this SPList list, string documentName, string documentUrl, DocumentSet docSet)
  SPFile file = null;
  SPListItem item = null;
  if (list is SPDocumentLibrary)
   SPDocumentLibrary docLib = (SPDocumentLibrary)list;
   if (docLib.ContentTypesEnabled)
    SPContentType myCType = list.ContentTypes["Link to a Document"];
    if (myCType != null)
       //replace string template with values
     string redirectAspx = RedirectAspxPage();
     redirectAspx.Replace("{0}", documentUrl);
       //should change the name of the .aspx file per item
     file = docSet.Folder.Files.Add(documentName + ".aspx", UTF8Encoding.UTF8.GetBytes(redirectAspx));
       //set list item properties
     item = file.Item;
         item["ContentTypeId"] = myCType.Id;
       if (item["ContentType"].ToString() == "Link to a Document")
      SPFieldUrlValue fieldUrl = new SPFieldUrlValue()
      { Description = documentName, Url = documentUrl };
        item["URL"] = fieldUrl;
    return file;
   public static string RedirectAspxPage()
  StringBuilder builder = new StringBuilder();
  builder.Append("<%@ Assembly Name='Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c' %>");
  builder.Append("<%@ Register TagPrefix='SharePoint' Namespace='Microsoft.SharePoint.WebControls' Assembly='Microsoft.SharePoint' %>");
  builder.Append("<%@ Import Namespace='System.IO' %>");
  builder.Append("<%@ Import Namespace='Microsoft.SharePoint' %>");
  builder.Append("<%@ Import Namespace='Microsoft.SharePoint.Utilities' %>");
  builder.Append("<%@ Import Namespace='Microsoft.SharePoint.WebControls' %>");   builder.Append("<html xmlns:mso=\"urn:schemas-microsoft-com:office:office\" xmlns:msdt=\"uuid:C2F41010-65B3-11d1-A29F-00AA00C14882\">");  builder.Append("<head>");
  builder.Append("<meta name=\"WebPartPageExpansion\" content=\"full\" /> <meta name='progid' content='SharePoint.Link' /> ");
  builder.Append("<!--[if gte mso 9]><SharePoint:CTFieldRefs runat=server Prefix=\"mso:\" FieldList=\"FileLeafRef,URL\"><xml>");
  builder.Append("<mso:ContentTypeId msdt:dt=\"string\">0x01010A00DC3917D9FAD55147B56FF78B40FF3ABB</mso:ContentTypeId>");
builder.Append("<mso:IconOverlay msdt:dt=\"string\">|docx|linkoverlay.gif</mso:IconOverlay>");  builder.Append("<mso:URL msdt:dt=\"string\">{0}, {0}</mso:URL>");
  builder.Append("</head>");  builder.Append("<body>");
  builder.Append("<form id='Form1' runat='server'>");
  builder.Append("<SharePoint:UrlRedirector id='Redirector1' runat='server' />");
  builder.Append("</form>");  builder.Append("</body>");  builder.Append("</html>");
  return builder.ToString();
share|improve this answer

Your Answer


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.