2

Currently I have created SharePoint Hosted App (Picture Slider) using Napa Office 365 Development tool. So far, I have created picture Library Manually, and now trying to create Picture Library using CSOM JavaScript in office 365

How to achieve this task?

  • Do you wanna create this library in Appweb? – Unnie Jul 8 '15 at 10:27
  • trying to create in Hostweb – Akshay Dattatray Nangare Jul 8 '15 at 10:40
4

Try this code to create the picture Library using Javscript:

function CreatePictureLibrary() {
  var context = SP.ClientContext.get_current();

  // *********** Host Web Change
  var hostUrl = GetUrlKeyValue("SPHostUrl");
  var hostContext = new SP.AppContextSite(context, hostUrl);
  var web = hostContext.get_web();
  // *********** Host Web Change

  var list=web.get_lists();
  var picLibCreation = new SP.ListCreationInformation(); 
  picLibCreation.set_title("MyDocumentLibrary"); //list title
  picLibCreation.set_templateType(SP.ListTemplateType.PictureLibrary); //Picture library type
  list.add(picLibCreation)
  context.load(list);
  context.executeQueryAsync(function(){
    alert(picLibCreation.title + "Created");
  }, function(){
    alert('Failed to Create the Document Library. Error:' + args.get_message());
  });
} 

If you want to create the library in Host web, change the way you generate context , rest code remains same.

  • ok ,i'm Working on It – Akshay Dattatray Nangare Jul 8 '15 at 10:55
  • 1
    I updated the code sample to add the list to the host web – Rob Windsor Jul 8 '15 at 11:08
  • @RobWindsor Perfect ! – Unnie Jul 8 '15 at 11:59

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.