Hi All,
In a following
post we will see how to create Folder inside Document Library using ECMA Script,
following code has been written for SP Hosted Apps.
In My Page I
have input Controls as follows, On clicking button I am crating folder with the
name specified in Text Box.
<div>
<p id="message">
<!-- The following content will be replaced with the
user name when you run the app - see App.js -->
initializing...
<input type="text" id="txtFolder"></input>
<br></br>
<input type="button"
id="btnCreateFolder"
value="CrateFolder"></input>
</p>
</div>
Below is the
code in App.js
'use
strict';
var
SPAppWebUrl;
var
spHostUrl;
(function () {
// This code
runs when the DOM is ready and creates a context object which is
// needed to
use the SharePoint object model
$(document).ready(function
() {
spHostUrl =
decodeURIComponent(getQueryStringParameter('SPHostUrl'));
SPAppWebUrl =
decodeURIComponent(getQueryStringParameter("SPAppWebUrl"));
$('#btnCreateFolder').on('click', function
() {
CreateFolder($('#txtFolder').val());
});
});
function
CreateFolder(folderName) {
var
context = SP.ClientContext.get_current();
var
parentContext = new SP.AppContextSite(context,
spHostUrl);
var web
= parentContext.get_web();
var
list = web.get_lists().getByTitle("MyDocLib");
var
listItemCreationInfo = new
SP.ListItemCreationInformation();
listItemCreationInfo.set_underlyingObjectType(SP.FileSystemObjectType.folder);
listItemCreationInfo.set_leafName(folderName);
var
newItem = list.addItem(listItemCreationInfo);
newItem.update();
context.load(web);
context.load(list);
context.executeQueryAsync(ExecuteOnSuccess, ExecuteOnFailure);
}
function
ExecuteOnSuccess() {
alert('folder
created successfully');
}
function
ExecuteOnFailure(sender, args) {
alert('error'
+ args.get_message());
}
function
getQueryStringParameter(urlParameterKey) {
var params
= document.URL.split('?')[1].split('&');
var
strParams = '';
for (var i = 0; i < params.length; i = i + 1) {
var
singleParam = params[i].split('=');
if
(singleParam[0] == urlParameterKey)
return
decodeURIComponent(singleParam[1]);
}
}
})();
Thanks.
Related Post
Apps.SharePoint 2013
- Get List Field Type using ECMA Script in SP Hosted Apps
- SharePoint 2013 AppModel Basics
- Something Went wrong error message while deploying App in SharePoint 2013
- Create Content Type using ECMA Script
- Get List Content Types using ECMA Script
- Get Lookup Column Value using ECMA Script
- Remove an App from SharePoint Site
- Delete List Item Collection using ECMA Script
- Get List Item attachments using ECMA Script
- XMLHttpRequest: Network Error 0x2eff, Could not complete the operation due to error 00002eff.
- Create SharePoint Hosted App in SharePoint 2013
- 101 New Features of Share Point 2013
- Creating Apps in SharePoint 2013
ECMA Script
- Get List Field Type using ECMA Script in SP Hosted Apps
- Get Choice Field Type Values using ECMA Script
- Executing Search Queries using ECMA Script in SharePoint 2013
- Create Site Column and Adding it to Content Type using ECMA Script
- Create Content Type using ECMA Script
- Get List Content Types using ECMA Script
- Get Lookup Column Value using ECMA Script
- Delete List Item Collection using ECMA Script
- Get List Item attachments using ECMA Script
- How to get List Items Count from SP List Using Visual webpart and ECMA script in SharePoint 2010
- How to get the List Items Count of SP List using ECMA Script in SharePoint 2010 ,2013
- SharePoint Client Object Model using ECMAScript in 2013
0 comments:
Post a Comment