Posts

Showing posts from 2017

SharePoint: Using PreSaveAction Function on custom list forms

https://social.technet.microsoft.com/wiki/contents/articles/31330.sharepoint-using-presaveaction-function-on-custom-list-forms.aspx 

Show calendar events in modal dialog in SharePoint 2013

Add the below code in the calendar view page using designer or add using script editor / content editor in the page where calendar view inserted < script src ="http://code.jquery.com/jquery-1.11.1.min.js" type ="text/javascript"></ script > < script type ="text/javascript">     $(document).ready( function () {         setInterval( function () {             $( "a[href*='DispForm.aspx']" ).each( function () {                 $( this ).attr( "onclick" , "openDialog('" + $( this ).text() + "','" + $( this ).attr( "href" ) + "')" );                 $( this ).attr( "href" , "javascript:void(0)" );                 $( this ).removeAttr( "target" );             });         }, 900);     });     function openDialog(title, url) {         var options = {             title: "Calendar - "

Set sender name using SPUtility.SendEmail

SPWeb oWeb = SPContext .Current.Web; StringDictionary headers = new StringDictionary (); string strFromEmailID = "Name to display <" + fromEmailAddress + ">" ; headers.Add( "from" , strFromEmailID); headers.Add( "to" , toEmail); headers.Add( "subject" , _subject); headers.Add( "content-type" , "text/html" ); System.Text. StringBuilder strMessage = new System.Text. StringBuilder (); strMessage.Append(_body); SPUtility .SendEmail(web, headers, strMessage.ToString());

Create Custom Field Type in SharePoint

Just follow the below steps to create a custom field type Its very simple to create a custom field type in SharePoint Step 1  : Open VS and create a new SharePoint Project Step 2:  Add SharePoint mapped folder                   - Control Templates Step 3 : Add another SharePoint Mapped folder                - XML Step 4: Then create user control named " MyField.ascx " and delete the code              file of the user control                          In our ascx file, delete the links to the code behind class and finally it                should be                                   <% @ Control Language ="C#" %> Step 5 : Add the below line in the ascx file               < SharePoint : RenderingTemplate ID ="MyRenderingTemplate" runat ="server">              < Template >                   < asp : TextBox ID ="txtMyField" runat ="server" CssClass ="ms-long" />

CONFIGURE ADFS 3.0 WITH SHAREPOINT 2013

https://blogit.create.pt/miguelmoreno/2014/11/14/configure-adfs-3-0-with-sharepoint-2013/ 

SharePoint 2010 Visual Upgrade Failed

Scenario :  I have faced visual upgrade failed issue after migrated the MOSS 2007 Content database to SharePoint 2010. Error which received during visual upgrade Visual Upgrade failed . The default master page for this user interface could not be found at “ /sites/site1/_catalogs/masterpage/v4.master ”. Add the requested master page at this path and try again. Then I have done the below thing to resolve the above issue 1. Created new sub site  2. Then i downloaded the V4.master file from the new site created 3. Uploaded the v4 master into site collection master page gallery  4. Tried visual upgrade  Its working without any issue.  i hope this will helps you...

Calculate financial year start and end date SQL Server

DECLARE @year INT = 2012 SELECT STDATE = DATEADD ( MONTH , 3 , DATEADD ( YEAR , DATEDIFF ( YEAR , 0 , DATEADD ( YEAR , @year - 1900 , 0 )), 0 )), ENDDATE = DATEADD ( DAY , - 1 , DATEADD ( MONTH , 3 , DATEADD ( YEAR , DATEDIFF ( YEAR , 0 , DATEADD ( YEAR , @year - 1900 , 0 ))+ 1 , 0 )))

Overview of the SharePoint Framework

https://dev.office.com/sharepoint/docs/spfx/sharepoint-framework-overview 

SharePoint 2013 suite bar

Method 1 $('div#suiteBarLeft .ms-core-brandingText').html("<span>Your preferable name</span> "); Method 2 .ms-core-brandingText:after{ content:"Your preferable name"; } .ms-core-brandingText{ margin-left: -90px; }

Rest API Call - Multiple SharePoint List

function GetListItems() {     function getJsonDataAsync(url) {               return $.ajax({             url: url,             method: "GET",             contentType: "application/json",             headers: {                 accept: "application/json;odata=verbose"             }         });     }     var ListData1 = _spPageContextInfo.webServerRelativeUrl + "/_api/lists/GetByTitle('listname1')"     var ListData2 = _spPageContextInfo.webServerRelativeUrl + "/_api/lists/GetByTitle('listname2')"         var response1= getJsonDataAsync(ListData1);     var response2= getJsonDataAsync(ListData2);           jQuery.when(response1, response2).done(function(resp1, resp2) {         //do ur code here     }); }

SharePoint 2013 "_spUserId" is undefined

_ spUserId is deprecated in SP2013. Use _ spPageContextInfo.userId instead.

SharePoint List : Check if the user has attached file

​​<script type="text/javascript" language="javascript"> function PreSaveAction() {     var attRow = document.getElementById("idAttachmentsTable");     if (attRow == null || attRow.rows.length == 0) { document.getElementById("idAttachmentsRow").style.display='none'; alert("Please attach the file. Attachment is mandatory"); return false ; } else { return true ;} } </script>​

SharePoint Form Digest

Form Digest Form Digest is used to insert a security validation for SharePoint pages. The digest value will be created by SharePoint server during page creation. Example:  A user loads a SharePoint page. He injected a script which updates the list data. When the user posts the page, the server will check Form Digest value against the page content. Thus, security attacks can be prevented. Viewing Form Digest You can use the view-source of a SharePoint page to see the form digest value. The value is stored under name  ___REQUESTDIGEST .

Read Document Library Items

 $().SPServices({     operation: "GetListItems",     async: false,     listName: "DOCUMENT LIBRARY",     CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='EncodedAbsUrl'/></ViewFields>",     completefunc: function (xData, Status) {       $(xData.responseXML).SPFilterNode("z:row").each(function() {         var doc = "<li><a href="+$(this).attr("ows_EncodedAbsUrl")+">" + $(this).attr("ows_Title") + "</a></li>";         $("#divTag").append(doc);       });     }   });

Retrieve SharePoint List Item Attachments using SPServices

$().SPServices({         operation: "GetAttachmentCollection",         async: false,         listName: "LIST NAME",         ID: ItemID,         completefunc: function(xData, Status) {             var attachments = [];               $(xData.responseXML).find("Attachment").each(function() {                var url = $(this).text();                attachments.push(url);             });                     }    });

SharePoint List Operations on SharePoint 2013 using REST API Services In - Part IV (GET All Items)

function GetItems() {       $.ajax     ({         url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('SharePoint List Name')/items?$select=Column1,Column2",         type: type,         data: data,         headers:         {             "Accept": "application/json;odata=verbose",             "Content-Type": "application/json;odata=verbose",             "X-RequestDigest": $("#__REQUESTDIGEST").val(),             "IF-MATCH": "*",             "X-HTTP-Method": null         },         cache: false,         success: function(data)           {     //success - bind values here             $("#sampleDIV").empty();             for (var i = 0; i < data.d.results.length; i++)               {                 var item = data.d.results[i];                 $("#sampleDIV").append(item.Column1);             }         },        

SharePoint List Operations on SharePoint 2013 using REST API Services In - Part III (DELETE)

function deleteItemByID(id) {     $.ajax     ({         url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('SharePoint List Name')/items("+id+")",         type: "POST",         headers:         {             "X-RequestDigest": $("#__REQUESTDIGEST").val(),             "IF-MATCH": "*",             "X-HTTP-Method": "DELETE"         },         success: function(data, status, xhr)         {             //alert("Success");         },         error: function(xhr, status, error)         {            //Failure         }     }); }  

SharePoint List Operations on SharePoint 2013 using REST API Services In - Part II (UPDATE)

function updateListItem(id) {     var titleVal = $("#txtTitle").val();     $.ajax     ({         url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('SharePoint List Name')/items("+id+")", // list item ID         type: "POST",         data: JSON.stringify         ({             __metadata:             {                 type: "SP.Data.TestListItem"             },             Title: titleVal         }),         headers:         {             "Accept": "application/json;odata=verbose",             "Content-Type": "application/json;odata=verbose",             "X-RequestDigest": $("#__REQUESTDIGEST").val(),             "IF-MATCH": "*",             "X-HTTP-Method": "MERGE"         },         success: function(data, status, xhr)         {             //alert("Success");         },  

SharePoint List Operations on SharePoint 2013 using REST API Services In - Part I (ADD)

Add List Item function AddItem() {     var titleVal = $("#txtTitle").val();      var metadataVal = {                 "__metadata": { "type": getListItemType("SharePoint List Name") },                 "Title": titleVal             };     $.ajax         ({         url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('SharePoint List Name')/items",         type: "POST",         data: JSON.stringify(metadataVal),         headers:         {             "Accept": "application/json;odata=verbose",             "Content-Type": "application/json;odata=verbose",             "X-RequestDigest": $("#__REQUESTDIGEST").val(),             "X-HTTP-Method": "POST"         },         success: function(data, status, xhr)         {             //alert("Success");         },         error: function(x

Opening SharePoint Links List in New Window

< script type ="text/javascript" language ="javascript" src ="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></ script > < script type ="text/javascript" language ="javascript">     $(document).ready( function () {         $( ".ms-vb a" ).attr( 'target' , '_blank' );     }); </ script >

SHAREPOINT / .NET C# EXPORT DATATABLE TO EXCEL USING OPENXML DLL

Convert DataTable to Stream private static MemoryStream WriteExcelFile (string sheetName , DataTable table ) {  MemoryStream stream = new MemoryStream();  using (SpreadsheetDocument document = SpreadsheetDocument.Create( stream , SpreadsheetDocumentType.Workbook,true))  {   WorkbookPart workbookPart = document.AddWorkbookPart();   workbookPart.Workbook = new Workbook();   WorksheetPart worksheetPart = workbookPart.AddNewPart<WorksheetPart>();   var sheetData = new SheetData();   worksheetPart.Worksheet = new Worksheet(sheetData);   Sheets sheets = workbookPart.Workbook.AppendChild(new Sheets());   Sheet sheet = new Sheet() { Id = workbookPart.GetIdOfPart(worksheetPart), SheetId = 1, Name = sheetName };   sheets.Append(sheet);   Row headerRow = new Row();   List<String> columns = new List<string>();   foreach (System.Data.DataColumn column in table .Columns)   {    columns.Add(column.ColumnName);    Cel