Tuesday, January 3, 2012

Inserting Listitem inside a SubFolder using Javascript Querying SharePoint

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default15.aspx.cs" Inherits="Default15" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script language="javascript" type="text/javascript" src="http://agmsm:9999/sites/Venkat/Sample/My%20Documents/SPAPI_Core.js"></script>
    <script language="javascript" type="text/javascript" src="http://agmsm:9999/sites/Venkat/Sample/My%20Documents/SPAPI_Lists.js"></script>
    <script language="javascript" type="text/javascript">
    function saveRecordInsideSubFolder()
    {
    var strUrl="http://agmsm:9999/sites/Venkat/Sample/";
        var lists = new SPAPI_Lists(strUrl);
        var FolderUrl=strUrl+"Lists/MyList/Testfolder2/"+document.getElementById("ddlSubFolderName").options(document.getElementById("ddlSubFolderName").selectedIndex).value;
        //alert(FolderUrl);
        //var res=lists.quickAddListItem();
        var strSaveItem=document.getElementById("txtSaveRecord").value;
        var res = lists.quickAddListItem('MyList', [{ Title:strSaveItem}],FolderUrl);
        if(res.status==200)
        {
            alert('Insertion Successful');
            alert(res.responseText);
        }
        else
        {
            alert('There was an error' +res.responseText);
        }

            document.getElementById("txtSaveRecord").value="";
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <select id="ddlSubFolderName">
    <option value="Select">Select</option>
    <option value="Test001">Test001</option>
    <option value="Test002">Test002</option>
    <option value="Test003">Test003</option>
    <option value="Test004">Test004</option>
    <option value="Test005">Test005</option>
    <option value="Test006">Test006</option>
    <option value="Test007">Test007</option>
    <option value="Test008">Test008</option>
    <option value="Test009">Test009</option>
    <option value="Test010">Test010</option>
    <option value="Test011">Test011</option>
    <option value="Test012">Test012</option>
    <option value="Test013">Test013</option>
    <option value="Test014">Test014</option>
    <option value="Test015">Test015</option>
    <option value="Test017">Test017</option>
    <option value="Test020">Test020</option>
    </select>
        <br />
        <input type="text" id="txtSaveRecord" />
        <br />
        <input type="button" onclick="saveRecordInsideSubFolder();" value="Save Record " id="Button1"/>
    </div>
    </form>
</body>
</html>

No comments:

Post a Comment