Hope you have idea how to create SharePoint App.
If you are using NAPA tool then replace below codes in APP.js file.
So i am just focusing on the REST script part to do the activities
I recommend to go through REST API for SP document libraries before proceed.
HTML file in Default.aspx
<div>
<p>
<b>Create Folder</b>
<br />
<input type="text" value="List Name Here" id="CreateFolder" />
<button id="btnclick">Create Folder</button>
</p>
</div>
----------------------
JS script in app.js (Paste the below methods in app.js file) Refer here
-----------------------
function FolderCreation()
{
var executor;
var getfoldername= document.getElementById("CreateFolder").value;
// Initialize the RequestExecutor with the app web URL.
executor = new SP.RequestExecutor(appweburl);
executor.executeAsync({
url: appweburl + "/_api/SP.AppContextSite(@target)/web/GetFolderByServerRelativeUrl('lib')/folders?@target='" + hostweburl + "'",
method: "POST",
body: "{ '__metadata':{ 'type': 'SP.Folder' }, 'ServerRelativeUrl':'Folder B' }",
}
headers:
{
"accept": "application/json; odata=verbose",
"content-type": "application/json; odata=verbose"
},
success: FoldersSuccessHandler,
error: FoldersErrorHandler
});
}
//Populate the selectFolders control after retrieving all of the folders.
function FoldersSuccessHandler(data) {
alert("Folder Created successfully in Library");
}
function FoldersErrorHandler(data, errorCode, errorMessage) {
alert("Could not Create a Folder in Library: " + errorMessage);
}
If you are using NAPA tool then replace below codes in APP.js file.
So i am just focusing on the REST script part to do the activities
I recommend to go through REST API for SP document libraries before proceed.
HTML file in Default.aspx
<div>
<p>
<b>Create Folder</b>
<br />
<input type="text" value="List Name Here" id="CreateFolder" />
<button id="btnclick">Create Folder</button>
</p>
</div>
----------------------
JS script in app.js (Paste the below methods in app.js file) Refer here
-----------------------
function FolderCreation()
{
var executor;
var getfoldername= document.getElementById("CreateFolder").value;
// Initialize the RequestExecutor with the app web URL.
executor = new SP.RequestExecutor(appweburl);
executor.executeAsync({
url: appweburl + "/_api/SP.AppContextSite(@target)/web/GetFolderByServerRelativeUrl('lib')/folders?@target='" + hostweburl + "'",
method: "POST",
body: "{ '__metadata':{ 'type': 'SP.Folder' }, 'ServerRelativeUrl':'Folder B' }",
}
headers:
{
"accept": "application/json; odata=verbose",
"content-type": "application/json; odata=verbose"
},
success: FoldersSuccessHandler,
error: FoldersErrorHandler
});
}
//Populate the selectFolders control after retrieving all of the folders.
function FoldersSuccessHandler(data) {
alert("Folder Created successfully in Library");
}
function FoldersErrorHandler(data, errorCode, errorMessage) {
alert("Could not Create a Folder in Library: " + errorMessage);
}
No comments:
Post a Comment