none
Attachments to Document Library item

    Question

  • I tried to create a custom Document Library where users can add attachments to uploaded documents. I made a copy of original SharePoint document library and renamed it for my own.

    After this I added DisableAttachments="FALSE" to my custom document library schema.xml file, defined a new content type in XML (its parent is Document content type) and added it to SharePoint's attachment field reference and other fields.

    After this I deployed both of my features and created a new document library from my custom document library template. I mapped to it previously created content type and was hoping to see Attach File link on EditForm.aspx and Dispform.aspx after creating a new document - but the link wasn't there.

    Do I have to change something more or we really can't attach files to Document Library items in Sharepoint 2007?
    Thursday, December 13, 2007 2:44 PM

Answers

  • I could be wrong but I'm pretty sure that restriction is hard coded into the API (I seem to remember seeing something when I was disassembling the API to figure something else out and if I'm remembering correctly there was code that was checking the base type and if it was a DocumentLibrary type then it was simply not allowing attachments - again, I could be thinking of something else).

     

    Thursday, December 13, 2007 4:14 PM

All replies

  • I could be wrong but I'm pretty sure that restriction is hard coded into the API (I seem to remember seeing something when I was disassembling the API to figure something else out and if I'm remembering correctly there was code that was checking the base type and if it was a DocumentLibrary type then it was simply not allowing attachments - again, I could be thinking of something else).

     

    Thursday, December 13, 2007 4:14 PM
  • It seems that while that feature is needed, adding further attachments to document library items indeed isn't possible - or at least no one has figured out how to do this. Before posting here I did quite a lot of googling, I found several forum posts asking how to do that - but unfortunately, no answers.
    Friday, December 14, 2007 8:46 AM
  • Thanks Garry and Sander for confirming what my exception was telling me.

    JFYI I was trying to programmatically add items to the attachments collection and SharePoint was throwing this ArgumentException:
    [ArgumentException: Value does not fall within the expected range.]
    Microsoft.SharePoint.SPFieldCollection.GetField(String strName, Boolean bThrowException) +249
    Microsoft.SharePoint.SPListItem.GetValue(String strName, Boolean bThrowException) +60
    Microsoft.SharePoint.SPListItem.GetValue(String strName) +32
    Microsoft.SharePoint.SPListItem.get_Attachments() +253

    This occurs when calling SPListItem.Attachments when your SPListItem is of a ContentType based upon Document

    -Gavin
    Thursday, December 27, 2007 10:24 AM
  • I was really hoping there was a way to add attachments to document library items because it would have made the knowledge base document library much more powerful for creating documentation.

    Right now, if I want to embed any pictures in kb article, they have to be external. Whereas, if I could just attach them to the article and link to them within the content, then it would make the article much more portable.

    If I want that sort of functionality, I could use a custom list, however then I loose the flexability of uploading PDF files (and other file types) directly to the document library.
    Thursday, March 26, 2009 6:12 PM
  • Hi,

     

    A bit late from the initial thread, but I've an explanation why the disableattachments is not use.

    In the file C:\Program Files\Fichiers communs\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\ctypes\ctypeswss.xml you can see that the document content type explicitly disable the attachments :

      <ContentType ID="0x0101"
        Name="$Resources:Document"
        Group="$Resources:Document_Content_Types"
        Description="$Resources:DocumentCTDesc"
        V2ListTemplateName="doclib"
        Version="0">
        <FieldRefs>
          <RemoveFieldRef ID="{67df98f4-9dec-48ff-a553-29bece9c5bf4}" Name="Attachments" /> <!-- Attachments -->
    ....
    
    I've tried to set up a new content type, that derived from the document content type. In this content type,I've added the attachments field. Unfortunately, the CT seems "broken" when deployed...

    • Proposed as answer by Pwł Thursday, March 15, 2012 2:25 PM
    Wednesday, June 02, 2010 2:06 PM
  • Hi, I followed Steve B's path in sp2010; same bit

    <ContentType ID="0x0101"       
    Name="$Resources:Document"       
    Group="$Resources:Document_Content_Types"       
    Description="$Resources:DocumentCTDesc"       
    V2ListTemplateName="doclib"       
    Version="0">       
    <FieldRefs>           
    <RemoveFieldRef ID="{67df98f4-9dec-48ff-a553-29bece9c5bf4}" Name="Attachments" /> <!-- Attachments -->

    ...


    has anyone come up with an elegant solution to this issue?

    I'm in the same boat as Sander, I need a document Library of PDF's and each one may or may not have 1 or more addendum Pdfs

    anyway if anyone has any pointers, workarounds, magic incantations, they'd be appreciated,

    what I'm thinking of doing is creating a second Document Library with a lookuplist to the Title of the first and storing the addendums there.

    Thursday, March 15, 2012 1:53 PM
  • Pwł, I guess this is a limitation due to the design of form library.

    In fact, if you look at how attachments are managed by SP, you will see it creates one folder for each ID and puts the attachment in this folder.

    In a document library, how would SharePoint differenciate what is a legitimate folder and what is an attachment folder ?

    Using some hated lookup, or maybe a custom field that stores the attachments, you may be able to do something.


    Paying back the community for its help by writing articles :
    Have a Nice Day.Net Blog

    Thursday, March 15, 2012 3:26 PM