Friday, May 24, 2013

Add Custom File Attachment Control in the Form of SharePoint

Normally SharePoint provides Document Attachment in the ribbon. But in my case ribbon was hide from the user. So I need to add Attachment Control on the form instead of ribbon. So I achieve it using Client Object Model. Insert the following code in your form to make attachment field available in the Form.

<tr>
<td rowspan="2" width="190px" valign="top" height="50px">
        <H3>
             Upload Evidence
        </H3>
     </td>
     <td valign="bottom" height="15" id="attachmentsOnClient">
         <span dir="ltr">
             <input type="file" name="fileupload0" id="onetidIOFile" size="56" title="Name" /> 
         </span>
     </td>
</tr>
<tr>
      <td colspan="4">
           <input id="attachOKbutton" type="BUTTON" onclick='OkAttach()' value="Upload" style="width: 12.8em; height: 2em"/>
           <span id="idSpace"/>
        </td>
</tr>

3 comments:

  1. I press ok but nothing happens, do u have any idea what should i do?

    ReplyDelete
  2. What do you mean by list page?
    All what I did is as follows:
    1-created a custom list.
    2-Openned sharepoint designer and created a new "newform" page.
    3- Added the above code to the newform aspx page.
    4- saved.
    5-Openned "new item" from the list (In sharepoint browser).
    the new form page is displayed with the new added upload control.
    6-I selected an item to attach, and pressed "ok"....nothing happens:(

    ReplyDelete
  3. Hi Noha,

    You are going absolutely fine. Could you please mention which SharePoint version you are using? I have tested this code with SharePoint 2010. Please also check if there is any JavaScript error occur in Browser console.

    ReplyDelete