Search This Blog

Thursday, January 15, 2015

Sharepoint Tips

 Export to excel from sharepoint List


Add a content editor webpart to the page containing content editor webpart then in html place copy the below code
  
<script type="text/javascript">

            function isIE() {
                return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
            }

            function exportToExcel() {
                var isIEBrowser = isIE();
                if (isIEBrowser == false) {
                    alert('Please use Internet Explorer for Excel Export Functionality.');
                    return false;
                }
                else {

 //Open the page in sharepoint designer, copy the list id and webpart id and copy in below red marked 
                                                               ListID                                                            Webpart ID
                    var strTableID = "{D3CAE8B9-A21A-4163-B0E7-08AD56E4395E}-{D9E5FC9C-C764-4382-BBBE-1CB670C34C1A}";                   
                    var detailsTable = document.getElementById(strTableID);
                    var objExcel = new ActiveXObject("Excel.Application");
                    var objWorkBook = objExcel.Workbooks.Add;
                    var objWorkSheet = objWorkBook.Worksheets(1);

                    for (var intRowIndex = 0; intRowIndex < detailsTable.rows.length; intRowIndex++) {
                        for (var intColumnIndex = 0; intColumnIndex < detailsTable.rows(intRowIndex).cells.length;
t
intColumnIndex++) {
                            if (intColumnIndex != 7)
                                objWorkSheet.Cells(intRowIndex + 1, intColumnIndex + 1) = detailsTable.rows(intRowIndex).cells

(intColumnIndex).innerText;
                        }
                    }
                    objExcel.Visible = true;
                    objExcel.UserControl = true;
                }
            }</script><div class="style1" style="text-align: left"><button onclick="exportToExcel()" type="submit" style="width: 98px">Export</button> </div>


 Limit Number of Characters using jQuery
<head> 
<title>Limit Number of Characters in a TextArea using Jquery</title>
<script type='text/javascript'>
src='http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js'></script> 
<script type='text/javascript'>
$(document).ready(function() {
$('.cssclassname').keyup(function() {
var len = this.value.length;
if (len >= 150) {
this.value = this.value.substring(0, 150);
}
$('#charLeft').text(150 - len);
});
});
</script>
</head>


 //export to excel from gridview in webpart
             StringWriter sw = new StringWriter();
             HtmlTextWriter writer = new HtmlTextWriter(sw);
             grdDasboard.RenderControl(writer);
             HttpContext.Current.Response.Clear();
             HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "DashboardReport.xls"));
             HttpContext.Current.Response.ContentType = "application/ms-excel";
             HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
             //render the htmlwriter into the response 
             HttpContext.Current.Response.Write(sw.ToString());
             HttpContext.Current.Response.End();  


//sharepoint postback to work after clicking on export to excel button

<script type="text/javascript" language="javascript">
if (typeof (_spBodyOnLoadFunctionNames) != ‘undefined’ && _spBodyOnLoadFunctionNames != null) {
_spBodyOnLoadFunctionNames.push("supressSubmitWraper");
}
function supressSubmitWraper() {
_spSuppressFormOnSubmitWrapper = true;
}
</script>


//css for setting the width of the column


<style type= "text/css">
nobr {white-space: normal};

width : 225px;
</style>


// css for word wrap of column header

<style type="text/css">

.ms-vh, .ms-vh2-nograd, .ms-vh2, .ms-vb

{white-space: normal;

text-align:center;
vertical-align:text-bottom;}

</style>

For Trimming First Character from the string

substring(strNames, 0,1)

For Trimming lastCharacter from the string

substring(strNames, 0,string-length(strNames)-1)

For getting only Year from Date time field

number(substring(field1, 1, 4))

For getting only Date from Date time field

number(substring(field1, 9, 2))

For getting month from Date time field

number(substring(field1, 6, 2))

 Limiting access to SharePoint site based on Active Directory Groups

You can control access to the system using a web application policy.

1) Go to the Central Administration web site
2) Click on Application Management
3) Click on Policy for Web application link in the  Application Security
section
4) On the Policy for Web Application page you will need to make sure you are
editing the policy for the web application you want to restrict access to
using the Web Application drop down on the right hand side of the toolbar
5) Click the Add Users button on the toolbar
6) Verify the correct Web Application is showing up and the Zone is set to
(All zones) then click Next
7) In the Choose Users section add an AD group for all the users you do NOT
want to access the system and give them the Deny All permission
8) Then click Finish
 
Server Error in ‘/’ Application. Runtime Error in SharePoint (Default error) 
 

when ever you are get this error you need do following 2 changes in your web.config file

1.  C:\inetpub\wwwroot\wss\virtualdirectories\<port>” go to the url modify the web.config file

a. In customErrors tag set mode="Off" to "On
b. In SafeMode tag set CallStack="true" to false
c. In Compilation tag Debug="false" to true

2.If still you are facing default error page then follow below change
In the layouts directory underneath the SharePoint root directory or 
14 hive – C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS

a. In customErrors tag set mode="Off" to "On
b. In SafeMode tag set CallStack="true" to false
c. In Compilation tag Debug="false" to true

CSS for Hiding Quick launch Bar in Sharepoint:

/*--Hide Quick Launch --*/
Add one content editor web part to page then add below css to it 


#s4-leftpanel{
display:none
}
.s4-ca{
margin-left:0px
}



If you want particular link in Quick launch go to site settings/Navigation 
give permission to the group who can view

 Hide “Add New Item” Link on the SharePoint 2010 List View Web Part:

The reason for this link is web part toolbar type property sets to the “Summary Toolbar” by default.

Change this setting to the “Full Toolbar” or “No Toolbar” and you will be able to hide the “Add New Item” link.

Customising All Responses View in Sharepoint Survey List 

Site Actions --> Edit Page --> Edit Survey Web Part >> Edit the current View

There we can change the view. i.e  add or delete fields and we can group the results and so on...

Learn details about Data view web part: 

http://www.sharepoint911.com/blogs/laura/Pages//Data%20View%20Web%20Part%20Screencasts.aspx


The current page has been customized from its template.Revert to template

The error message which usually comes when you modify any page using SharePoint designer. 
The error message was "The current page has been customized from its template. Revert to template". 
Here if you will click on the Revert to template then the modifications will not be saved.

In my point of view this is a warning message which you can hide like below:

Open share point designer, click on master page and then Right click on the  current master page 
(v4.master is by default) and then click on Check out. Now then right click on the master page and click on 
Edit file in Advanced mode.

This will open the file in Edit mode. Now search for s4-statusbarcontainer. And modify according to below:

<!--div id="s4-statusbarcontainer">
    <div id="pageStatusBar" class="s4-status-s1">
    </div>
</div-->

Sign in as Different User in SharePoint 2013 
  1. Locate and then open the following file in a text editor:  C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\CONTROLTEMPLATES\Welcome.ascx

  2. Add the following element before the existing "ID_RequestAccess" element:
    <SharePoint:MenuItemTemplate runat="server" ID="ID_LoginAsDifferentUser" Text="<%$Resources:wss,personalactions_loginasdifferentuser%>" Description="<%$Resources:wss,personalactions_loginasdifferentuserdescription%>" MenuGroupId="100" Sequence="100" UseShortId="true" />

  3. Save the file

No comments:

Post a Comment