using document library or form library

73 Views Asked by At

Sorry if my question is not good because I am new to sharepoint.

I have some document in document library I like to other people can come to library and put their comment there.

with using InfoPath designer form and repeated section and publishing form to form library I can data entry in the fields of InfoPath and upload attachment and then submit to form library and then other users can come and put their comment in the form.

now my problem is, my files are in document library and all meta data there is in document library. now my question is if I want to put comments on each Document i have to make a form library and again data entry all meta data in InfoPath form and upload attachments,....and then publish.

  it seems it is a duplicate job, I like to know what is the best practice in this case?
  I like to know I have to start with form library from scratch?

i note i am using sharepoint server 2013 and InfoPath from.

1

There are 1 best solutions below

0
Masoud On

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
Library
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()
{
((ButtonEvent)EventManager.ControlEvents["SubmitButton"]
).Clicked
+= 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",
this.NamespaceManager);
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);
}
Deployment
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