0

I Have a requirement for having a word document in each and every list item that i create. Suppose i click on new item in sharepoint list, the new item form must contain an embedded word document by default.

3
  • 1
    Do you mean the NewItem form has to have a Word document (like a policy doc or something) showing in it, or that each new list item must have a blank Word document attached to it when it's created?
    – Omegacron
    Apr 29 '14 at 17:31
  • @ Omegacron I mean the NewItem form has to have a Word document (like a policy doc or something) showing in it
    – Avinash
    Apr 29 '14 at 18:56
  • Thanks for the update - I added an answer that covers various ways to do that.
    – Omegacron
    Apr 29 '14 at 19:18
3

What you have described is the functionality of Document Libraries. You can provide a custom document template for the library. (It may make more sense to provide a custom document template at the Content Type instead of the library.)

1
  • I need to use it for a list item, i mean i have a list and if i create a new list item, that newform.aspx for that listitem must have an embedded word document in it. This must be the case for all list items
    – Avinash
    Apr 29 '14 at 18:56
0

To actually embed a document WITHIN a SharePoint New Item form, there are a few options available:

  • If the document is static (i.e. - a policy document that doesn't change often), you can save or print the document to a PDF stored somewhere within SharePoint, then add a Page Viewer web part to the form and point it to the PDF file. This is an OOTB method for displaying a PDF file using an iFrame web part, but it only works with certain file types (and Word isn't one of them).
  • If the document is updated frequently, and/or PDF format won't work, you can create a blank HTML or ASPX page wherein the Word document is embedded as an object. This approach will likely require the creation of an ActiveX object to render the Word document within the browser. On your SharePoint form, you can then place a Content Editor web part and display the web page using an iFrame.
  • If the document will change depending on values selected within the form (like a Department field), your best bet is probably the CEWP/iFrame option above with some JavaScript or JQuery added which changes the SRC attribute of the iFrame based on the field value.
  • If you need Word functionality within the displayed document, you can code up a custom object in C# that renders the document using Word App functionality.

UPDATE: If you have SharePoint 2013, it looks like it has an OOTB method for embedding a read-only copy of the Word document within an ASPX page. See the link below for details:

How to Embed a Word Document in a SharePoint 2013 Page

Another option might be Google Docs Viewer.

Hopefully, one of these will help.

5
  • i think the second option will be more suited to me, can u give more explanation regarding what should be done?
    – Avinash
    Apr 29 '14 at 19:34
  • I am not able to see the iframe information i mean the embed information
    – Avinash
    Apr 29 '14 at 20:14
  • It's been ages since I've done anything with ActiveX, but I did find someone recommending Google Docs Viewer. I've never used it, but it certainly looks promising. I've added the link to my answer.
    – Omegacron
    Apr 29 '14 at 20:48
  • i don't think ActiveX is right Choice Apr 30 '14 at 4:08
  • You may have to go with Google Docs Viewer or the 4th option above - depends on if you only need to view the doc or have full Word functionality. The 4th option uses the Office webapp API so it's a full coded solution. I've never done that myself, as I've never had a business requirement that justified the development time involved.
    – Omegacron
    Apr 30 '14 at 16:54
0

We Can use event receiver to save every item with Attachment. And to show that Attachment in NewItem.aspx form we can embed simply using Html

0

Based on your question, it sounds like you want the attachments field to be required and you want to make sure that it is a word file (*.doc).

Here is a snippet of some code that I used to require an attachment.

function PreSaveAction() {
    var attachment = document.getElementById("idAttachmentsTable");
    if (attachment === null || attachment.rows.length === 0) {
        alert("No attachments found. Please attach the required file(s).");
        return false;
    } else {
        return true;
    }
}

Now if you wanted to make sure that it was a .doc that was uploaded, the attachments names are stored in this element as well. You can run a check on the document name.

UPDATE:

<tr id="idAttachmentsRow">
    <td nowrap="true" valign="top" class="ms-formlabel">
        <SharePoint:FieldLabel ControlMode="New" FieldName="Attachments" runat="server" />
    </td>
    <td valign="top" class="ms-formbody">
        <SharePoint:FormField runat="server" id="AttachmentsField" ControlMode="New" FieldName="Attachments" __designer:bind="{ddwrt:DataBind('i','AttachmentsField','Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Attachments')}" />
        <script>
            var elm = document.getElementById( & quot; idAttachmentsTable & quot;);
            if (elm == null || elm.rows.length == 0) document.getElementById( & quot; idAttachmentsRow & quot;).style.display = & apos;
            none & apos;;
        </script>
    </td>
</tr>
<tr>
    <td rowspan="2" width="190px" valign="top" height="50px">Add Attachments:</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"></span>
    </td>
</tr>
2
  • But the user needs to know he needs to attach a file, i mean the requirement is that the user should be able to see an icon on the page. So when he clicks on the icon the word document would open up
    – Avinash
    Apr 30 '14 at 15:36
  • I have updated my answer to include the code that I used to display attachments in my CustomNewForm.aspx. the only thing it doesn't do is allow you to download the attachment you just uploaded (not really necessary right?) Apr 30 '14 at 21:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.