sp-attachment-library

This is library is used ro do attachments realted actions on a list item in Sharepoint Angular SPA Addins.

Usage no npm install needed!

<script type="module">
  import spAttachmentLibrary from 'https://cdn.skypack.dev/sp-attachment-library';
</script>

README

SharePoint Attachment Controller for SPA Addins

This library includes a component and service which we can use for actions related sharepoint list item attachments

  • sp-attachment(component)
  • SpAttachmentLibraryService(service)

How to install and use

npm install sp-attachment
  • Import the module: Import the module:
//...
import { SpAttachmentLibraryModule, SpAttachmentConfig, SpAttachmentLibraryService } from 'sp-attachment-library';

const spAttachmentconfig: SpAttachmentConfig = {
// here I have used sp-rest-proxy to test it locally for dev mode
  baseUrl: isDevMode() ? 'http://localhost:8181' : (window as any)._spPageContextInfo.siteAbsoluteUrl,
};

@NgModule({
  //...
  imports: [
    //...
    SpAttachmentLibraryModule,
    SpAttachmentLibraryModule.forRoot(spAttachmentconfig)
  ],
   providers: [
   //...
   SpAttachmentLibraryService
   ],
  //...
})
export class AppModule { }
  • Example Use
<sp-attachment [listName]="'TestList'" [itemId]='1'></sp-attachment>
  • Service Use
//...
import { SpAttachmentLibraryService } from 'sp-attachment-library';

export class SampleComponent {

    constructor(
        private spAttachmentLibraryService: SpAttachmentLibraryService) {
    }

    loadAttachments() {
        this.spAttachmentLibraryService.getAttachmentsById(this.listName, this.itemId).then((data) => {
            // implement logic here
        }).catch((error) => {
            // handle error here
        });
    }
}

Functions

  • getAttachmentsById(listName: string, itemId: number)
  • addAttachment(listName: string, itemId: number, attachment: AttachmentFileInfo)
  • addAttachments(listName: string, itemId: number, attachments: AttachmentFileInfo[])
  • deleteAttachment(listName: string, itemId: number, fileName: string)
  • deleteAttachments(listName: string, itemId: number, fileNames: string[])
  • getAttachmentContent(listName: string, itemId: number, fileName: string)
  • updateAttachmentContent(listName: string, itemId: number, fileName: string, content: string | Blob | ArrayBuffer)

Demo


⚠ Note

This library needs some modification.

Todos

  • Write MORE Tests
  • Add better styling