Tuesday, May 29, 2012

ECMA SCRIPT SHAREPOINT 2010

SharePoint provides two sets of JavaScript file: minified and unminified/debug version.
For example sp.js file is minified and sp.debug is minified and debug version. The default master page in SharePoint has a scriptmanager in the page and whose ScriptMode is set to auto, as a result the minified version of js file loaded.
If you want to use debug version you can add the <deployment retail="false" /> in the <system.web> section of the web.config. In the production you need to remove this entry to make sure minified version is used.

Managed Client
DLL's needed : Microsoft.SharePoint.Client.dll, Microsoft.SharePoint.Client.Runtime.dll. Find these files in the 14/ISAPI folder. Usually, the location would be at "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI".

Silverlight
Microsoft.SharePoint.Client.Silverlight.dll and Microsoft.SharePoint.Client.Silverlight.Runtime.dll. They find at "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin".

ECMAScript
SP.js file - The file fund at "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS".

SharePoint object model syntax:-
Server side syntax        Client side syntax 
SPContext                    ClientContext
SPSite                          Site
SPWeb                        Web
SPList                          List

After saving the .js file, press Ctrl + Shift + J to update the JavaScript IntelliSense.
Tip: Sometimes, you might have to press Ctrl + Shift + J for each .js file referenced.

please replace the below lines.... : http://msdn.microsoft.com/en-us/library/ee535709.aspx
{code}
<script type=”text/ecmascript” src=”/_layouts/SP.Core.js” />
<script type=”text/ecmascript” src=”/_layouts/SP.Debug.js” />
<script type=”text/ecmascript” src=”/_layouts/SP.Runtime.Debug.js” />
{code}
With
{code}
<SharePoint:ScriptLink ID=”ScriptLink1″ Name=”sp.debug.js” LoadAfterUI=”true” Localizable=”false” runat=”server” />
{code}

<!-- http://msdn.microsoft.com/en-us/library/ff798328.aspx -->
    <script type="text/javascript" src="/_layouts/SP.debug.js" ></script>
    <%--  CreateList --%>
    <script type="text/javascript">
        var clientContext = null;
        var web = null;
        ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
        function Initialize() {
            clientContext = new SP.ClientContext.get_current();
            web = clientContext.get_web();
            var itemCreateInfo = new SP.ListItemCreationInformation();
            var listCreationInfo = new SP.ListCreationInformation();
            listCreationInfo.set_title('My Custom Generic List');
            listCreationInfo.set_templateType(SP.ListTemplateType.genericList);
            this.oList = web.get_lists().add(listCreationInfo);

            clientContext.load(oList, 'Title', 'Id');

            clientContext.executeQueryAsync(Function.createDelegate(this, this.onListCreateSuccess),
Function.createDelegate(this, this.onQueryFailed));
        }
        function onListCreateSuccess(sender, args) {
            alert("List title : " + this.oList.get_title() + "; List ID : " + this.oList.get_id());
        }

        function onQueryFailed(sender, args) {
            alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
        }</script>
    ​
    <%--  CreateSite --%>
    <script type="text/javascript">
        var clientContext = null;
        var web = null;
        ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
        function Initialize() {
            clientContext = new SP.ClientContext.get_current();
            web = clientContext.get_web();
            var webCreateInfo = new SP.WebCreationInformation();
            webCreateInfo.set_description("All about Rare solutions.");
            webCreateInfo.set_language(1033);
            webCreateInfo.set_title("Rare Solutions - SharePoint and .NET");
            webCreateInfo.set_url("RareSolutionsSharePoint");
            webCreateInfo.set_useSamePermissionsAsParentSite(true);
            webCreateInfo.set_webTemplate("BLOG#0");

            this.oNewWebsite = this.web.get_webs().add(webCreateInfo);

            clientContext.load(this.oNewWebsite, 'ServerRelativeUrl', 'Created');

            clientContext.executeQueryAsync(Function.createDelegate(this, this.onCreateWebSuccess),

Function.createDelegate(this, this.onQueryFailed));
        }
        function onCreateWebSuccess(sender, args) {
            alert("Web site url : " + this.oNewWebsite.get_serverRelativeUrl());
        }

        function onQueryFailed(sender, args) {
            alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
        }</script>
    ​
    <%--     DeleteList--%>
    <script type="text/javascript">
        var clientContext = null;
        var web = null;
        ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
        function Initialize() {
            clientContext = new SP.ClientContext.get_current();
            web = clientContext.get_web();
            this.list = web.get_lists().getByTitle('My custom generic list');
            list.deleteObject();

            clientContext.executeQueryAsync(Function.createDelegate(this, this.onListDeleteSuccess),

Function.createDelegate(this, this.onQueryFailed));
        }
        function onListDeleteSuccess(sender, args) {
            alert("list deleted");
        }

        function onQueryFailed(sender, args) {
            alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
        }</script>
    ​
    <%-- DeleteListItem --%>
    <script type="text/javascript">
        var clientContext = null;
        var web = null;
        ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
        function Initialize() {
            clientContext = new SP.ClientContext.get_current();
            web = clientContext.get_web();
            this.list = web.get_lists().getByTitle('My custom generic list');
            this.oListItem = list.getItemById(1);
            oListItem.deleteObject();

            clientContext.executeQueryAsync(Function.createDelegate(this, this.onListItemDeleteSuccess),

Function.createDelegate(this, this.onQueryFailed));
        }
        function onListItemDeleteSuccess(sender, args) {
            alert("list item deleted");
        }

        function onQueryFailed(sender, args) {
            alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
        }</script>
    ​
    <%--  DeleteSite --%>
    <script type="text/javascript">
        var clientContext = null;
        var web = null;
        ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
        function Initialize() {
            clientContext = new SP.ClientContext.get_current();
            web = clientContext.get_web();
            this.website = web.get_webs().getByTitle('Rare Solutions');
            website.deleteObject();

            clientContext.executeQueryAsync(Function.createDelegate(this, this.onSiteDeleteSuccess),

Function.createDelegate(this, this.onQueryFailed));
        }
        function onSiteDeleteSuccess(sender, args) {
            alert("site deleted");
        }

        function onQueryFailed(sender, args) {
            alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
        }</script>
    ​
    <%-- LoadListData --%>
    <script type="text/javascript">
        var clientContext = null;
        var web = null;
        ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
        function Initialize() {
            clientContext = new SP.ClientContext.get_current();
            web = clientContext.get_web();
            this.list = web.get_lists().getByTitle("Images");
            clientContext.load(list, 'Title', 'Id');
            clientContext.executeQueryAsync(Function.createDelegate(this, this.onListLoadSuccess),
Function.createDelegate(this, this.onQueryFailed));
        }
        function onListLoadSuccess(sender, args) {
            alert("List title : " + this.list.get_title() + "; List ID : " + this.list.get_id());
        }

        function onQueryFailed(sender, args) {
            alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
        }</script>
    ​
    <%-- LoadListItemsData --%>
    <script type="text/javascript">
        var clientContext = null;
        var web = null;
        ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
        function Initialize() {
            clientContext = new SP.ClientContext.get_current();
            web = clientContext.get_web();
            var list = web.get_lists().getByTitle("Pages");
            var camlQuery = new SP.CamlQuery();
            var q = '<View><RowLimit>5</RowLimit></View>';
            camlQuery.set_viewXml(q);
            this.listItems = list.getItems(camlQuery);
            clientContext.load(listItems, 'Include(DisplayName,Id)');
            clientContext.executeQueryAsync(Function.createDelegate(this, this.onListItemsLoadSuccess),
Function.createDelegate(this, this.onQueryFailed));
        }
        function onListItemsLoadSuccess(sender, args) {
            var listEnumerator = this.listItems.getEnumerator();
            //iterate though all of the items
            while (listEnumerator.moveNext()) {
                var item = listEnumerator.get_current();
                var title = item.get_displayName();
                var id = item.get_id();
                alert("List title : " + title + "; List ID : " + id);
            }
        }

        function onQueryFailed(sender, args) {
            alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
        }</script>
    ​
    <%-- LoadSiteData --%>
    <script type="text/javascript">
        var clientContext = null;
        var web = null;
        ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
        function Initialize() {
            clientContext = new SP.ClientContext.get_current();
            web = clientContext.get_web();
            clientContext.load(web, 'Title');
            clientContext.executeQueryAsync(Function.createDelegate(this, this.onSiteLoadSuccess), Function.createDelegate(this, this.onQueryFailed));
        }
        function onSiteLoadSuccess(sender, args) {
            alert("site title : " + web.get_title());
        }

        function onQueryFailed(sender, args) {
            alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
        }</script>
    ​
    <%--  UpdateList --%>
    <script type="text/javascript">
        var clientContext = null;
        var web = null;
        ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
        function Initialize() {
            clientContext = new SP.ClientContext.get_current();
            web = clientContext.get_web();
            this.list = web.get_lists().getByTitle('My custom generic list');
            list.set_description('My custom generic list description');
            list.update();
            clientContext.load(list, 'Description');
            clientContext.executeQueryAsync(Function.createDelegate(this, this.onSiteLoadSuccess), Function.createDelegate(this, this.onQueryFailed));
        }
        function onSiteLoadSuccess(sender, args) {
            alert("list description : " + this.list.get_description());
        }

        function onQueryFailed(sender, args) {
            alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
        }</script>
    ​
    <%--  UpdateListItem --%>
    <script type="text/javascript">
        var clientContext = null;
        var web = null;
        ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
        function Initialize() {
            clientContext = new SP.ClientContext.get_current();
            web = clientContext.get_web();
            this.list = web.get_lists().getByTitle('My custom generic list');
            this.oListItem = list.getItemById(1);
            oListItem.set_item('Title', 'Praveen Battula Updated');
            oListItem.update();

            clientContext.executeQueryAsync(Function.createDelegate(this, this.onUpdateListItemSuccess), Function.createDelegate(this, this.onQueryFailed));
        }
        function onUpdateListItemSuccess(sender, args) {
            alert("list item updated");
        }

        function onQueryFailed(sender, args) {
            alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
        }
</script>

Date Comparison ASP.NET + JAVA SCRIPT

Download Ajax Control Tool Kit form here
http://ajaxcontroltoolkit.codeplex.com/releases/view/33804

How to Add Ajax Toolkit to SharePoint Web.Config Refer below Link
http://inspiredbytechnology.com/using-ajax-control-toolkit-sharepoint-2010/

<%@ Register Assembly="AjaxControlToolkit, Version=3.0.30930.28736, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"
    Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>


<script type="text/javascript">
        function ValidateDates(sender, args) {
            var fromDate = document.getElementById('<%= txtMyDate.ClientID %>').value;

            var validformat = /^\d{2}\/\d{2}\/\d{4}$/
            if (!validformat.test(fromDate)) {

                sender.errormessage = "Invalid Date Format. Please correct and submit again. ";
                args.IsValid = false;
                return false;
            }
            else {
                var dayfield = fromDate.split("/")[0]
                var monthfield = fromDate.split("/")[1]
                var yearfield = fromDate.split("/")[2]
                var dayobj = new Date(yearfield, monthfield - 1, dayfield)
                if ((dayobj.getMonth() + 1 != monthfield) || (dayobj.getDate() != dayfield) || (dayobj.getFullYear() != yearfield)) {

                    sender.errormessage = "Invalid Day, Month, or Year range detected. Please correct and submit again. ";
                    args.IsValid = false;
                    return false;
                }
                else {
                    var dtToday = new Date();
                    if (dayobj > dtToday) {
                        args.IsValid = false;
                        return false;
                    }
                    else {
                        args.IsValid = true;
                        return true;
                    }
                }
            }
        };  
    </script>


 <asp:ValidationSummary ID="ValidationSummary1" HeaderText="Please enter valid values for the following field(s)"
                    DisplayMode="BulletList" EnableClientScript="true" runat="server" ValidationGroup="valGroup1"
                    CssClass="error_msg" />



 <asp:TextBox ID="txtMyDate" runat="server" CssClass="myDesign"></asp:TextBox>


<img id="imgMyImage" src="/_layouts/images/MyProject/calander.png" width="20"
                                                height="20" alt="" class="icon" />
                                            <div style="width: 50px; position: relative;">
                                                <ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtMyDate "
                                                    Format="dd/MM/yyyy" PopupButtonID="imgMyImage" CssClass="cal_Theme1" />
                                            </div>
                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="txtMyDate"
                                                ErrorMessage="Date of Purchase" Display="None" ValidationGroup="valGroup1" Text="*">
                                            </asp:RequiredFieldValidator>
                                            <asp:CustomValidator ID="CustomDateValidator" runat="server" ErrorMessage="Please ensure that 'Date of Purchase' is lesser than or equal to 'Current Date'."
                                                ClientValidationFunction="ValidateDates" Display="None" ValidationGroup="valGroup1"> </asp:CustomValidator>



<asp:Button ID="btnSave" runat="server" Text="Add" OnClick="btnSave_Click" CssClass="button"
                                                ValidationGroup="valGroup1" />
-----------------------------------------------------------------------------------------------------------


<html>
<head>
<script  language="javascript">
function cal()
{
document.f1.y1.value= mydiff(document.f1.n1.value,document.f1.n2.value,"days");
}
function mydiff(date1,date2,interval) {
var second=1000, minute=second*60, hour=minute*60, day=hour*24, week=day*7;
    date1 = new Date(date1);
    date2 = new Date(date2);
    var timediff = date2 - date1;
        return Math.floor(timediff / day);
}        
</script>
</head>
<body>

<form name="f1">
       enter From Date:<input type="text" name="n1">
   <br>enter To Date:<input type="text" name="n2">
   <br>No Of Days: <input type="text" name="y1">
   <input type="button"  value="Get Days"  name="ab" onclick="cal();">
</form>
</body>
</html>




Monday, May 28, 2012

Property or indexer 'Microsoft.SharePoint.SPListItem.Title' cannot be assigned to -- it is read only


Property or indexer 'Microsoft.SharePoint.SPListItem.Title' cannot be assigned to -- it is read only :-



 protected void btn1_Click(object sender, EventArgs e)
        {
            using (SPSite site = new SPSite(SPContext.Current.Site.Url))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists["Announcements"];
                    SPListItem item = list.AddItem();
                    item["Title"] = "New Announcement";
                    item.Update();
                }
            }
        }


SharePoint Version


Featured Post

Protect an API by using OAuth 2.0 with Azure Active Directory and API Management

Protect an API by using OAuth 2.0 with Azure Active Directory and API Management https://docs.microsoft.com/en-us/azure/api-management/api-...

Popular posts