sp-attachment-library
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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

Package Sidebar

Install

npm i sp-attachment-library

Weekly Downloads

1

Version

1.0.1

License

none

Unpacked Size

571 kB

Total Files

42

Last publish

Collaborators

  • kogul.ceymplon