Confuse between using form library or document library

Brass Contributor


I have a Document library in sharepoint 2013 server that there are several folders and inside of each folder 2 or 3 files. All has been done with browser without using InfoPath and all of requires meta data there is in Document library.

Now several people want to come and put some note or comment below each Document no.


With designing a InfoPath form and publish to form library I can make my requires form and fields I need, but my problem is a duplicate job I have to data entry a gain all the data I have in document library in the form library. Can you helped me about this scenario because I have stopped more than of 2 yeas in this problem. And I do not know what is the best practice?


how i can solve my problem step by step? very appreciate for any guidance.

also i noted i am using sharepoint 2013 with InfoPath.

1 Reply
best response confirmed by Masoud1313 (Brass Contributor)
I think I found my answer in the below link address:

[Uploading File Attachment Into a Folder in a SharePoint Document Library Using InfoPath Form][1]

, with uploading InfoPath attachments in separate document library my problem will be solved. because i wanted my files in the document library folders and also can use features of InfoPath form with using repeated section.

now at first i use InfoPath from in form library and attach required files and then after submitting, the attaches files will be upload in document library of sharepoint.

also I found in the book (infopath with sharepoint 2013 how to) appendix B:

Appendix B. Upload File Attachments in Forms to a Document
This appendix presents a code-behind method that uploads an attached file to a separate document
library when the form is submitted. The code here was adapted from Pranab Paul’s blog on MSDN.
Form Scenario
The form used in this scenario contains a file attachment control with a field named fileAttach. There
is also a button to be used as a submit button with and ID of SubmitButton.
The user may upload a file to the form and then submit the form. There is a form library in SharePoint
to which to submit the InfoPath form instance, but there is also a document library in which the file
attached to the form needs to be uploaded. A data connection for submission has been created and
points to the form library.
The form contains code-behind and therefore must have Full Trust. It also must be published as an
Administrator-Approved form and then added to Form Services in SharePoint.
Submit Button and Code-Behind Setup
The custom submit button needs to have a rule added such that when the button is clicked the Submit
Data action is executed. Also, in the button properties you need to click Edit Code to produce the
button event handler and method in the code-behind:
Click here to view code image
public void InternalStartup()
+= new ClickedEventHandler(SubmitButton_Clicked);
public void SubmitButton_Clicked
(object sender, ClickedEventArgs e)
// Write your code here.
The code-behind project uses SharePoint functions and therefore needs a reference to the
Microsoft.SharePoint assembly. This is a similar requirement in the tracking changes solution
described in Chapter 17, “Track Changes in a Form,” so you may refer to those steps to include the
proper assembly reference in this file attachment solution.
Event Handler Code
Within the button event handler (SubmitButton_Clicked) you need code to perform the
retrieval of the attached file and the upload of that file to a document library. The code to perform this
is shown here:
Click here to view code image
public void SubmitButton_Clicked(object sender, ClickedEventArgs e)
XPathNavigator docXN = this.CreateNavigator();
XPathNavigator opnXN = docXN.SelectSingleNode("/my:myFields/my:fileAttach",
byte[] attachmentNodeBytes = Convert.FromBase64String(opnXN.ToString());
// Position 20 contains a DWORD indicating the length of the
// filename buffer. The filename is stored as Unicode so the
// length is multiplied by 2.
int fnLength = attachmentNodeBytes[20] * 2;
byte[] fnBytes = new byte[fnLength];
// The actual filename starts at position 24...
for (int i = 0; i < fnBytes.Length; i++)
fnBytes[i] = attachmentNodeBytes[24 + i];
// Convert the filename bytes to a string. The string
// terminates with \0 so the actual filename is the
// original filename minus the last character !
char[] charFileName = System.Text.UnicodeEncoding.Unicode.GetChars(fnBytes);
string fileName = new string(charFileName);
fileName = fileName.Substring(0, fileName.Length - 1);
// The file is located after the header, which is 24 bytes long
// plus the length of the filename.
byte[] fileContents = new byte[attachmentNodeBytes.Length - (24 + fnLength)];
for (int i = 0; i < fileContents.Length; ++i)
fileContents[i] = attachmentNodeBytes[24 + fnLength + i];
string SiteURL = "http://SharePointRoot/DocumentLibrary/" + fileName;
SPWeb site = new SPSite(SiteURL).OpenWeb();
site.Files.Add(SiteURL, fileContents);
As mentioned earlier, you need to publish the form as an Administrator-Approved form and then
upload the form template to Form Services in SharePoint. Once you upload it to Form Services, you
may use the form as the content type in the desired form library.
When a new form is instantiated and submitted, the form instance is saved in the form library you
specified in the data connection for submission, and the attached file is stored in the document library
you specified within the code-behind