Monday 16 December 2013

Access denied for the page.
Sharepoint 2013 office 365
 web site publishing pages created from a template using jsom are throwing access denied error for the users who is having read access to the pages. If the user permissions changed to full control also keep on getting the error.

Workaround: added read permission for the "everyone" to the style library the where my custom .css and image files are stored.



Thursday 12 December 2013

Get all Sharepoint site collection groups and Delete them using custom ui.


<script type="text/javascript" src="/SiteAssets/Tabs/jquery.min.js"></script>

<style type="text/css" rel="stylesheet">
a:visited{ color: gray }
delete:visited{ color: gray }
#delete{
color:red;
}
</style>

<script type="text/javascript" language="javascript">
var webs;
function loadWebs() {
   var clientContext = SP.ClientContext.get_current();
   this.webs = clientContext.get_site().get_rootWeb().get_webs();
   clientContext.load(this.webs);
   clientContext.executeQueryAsync(Function.createDelegate(this, this.onWebsLoaded), Function.createDelegate(this, this.onQueryFailed));
}

function onQueryFailed(sender, args) {
   alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}
var grpdescription2 = "Description.";
function onWebsLoaded(sender, args) {
   for (var i = 0; i < this.webs.get_count(); i++) {
   var sitetitle =  this.webs.itemAt(i).get_title();
   var url = this.webs.itemAt(i).get_serverRelativeUrl();
 
   var itemid = replacespecialitems(url);
     jQuery("#data").append(" <li id='"+itemid+"'><table><tr><td class='ms-vb'><a href='/_layouts/Deletesite.aspx'>" +sitetitle +"</a> &nbsp;&nbsp;&nbsp;</td><td>&nbsp;"+url +"</td><td>&nbsp;&nbsp;<a id='noSub &quot;"+itemid+"&quot;' href='javascript:;' onclick='javascript:DeleteSubWeb( &quot;"+url+"&quot; )' >&nbsp;&nbsp; Delete Web sites&nbsp;&nbsp; </a> </td></tr></table></li>");
 
   }  
}

function replacespecialitems( url){

// to escape special charecters. wright ur own
url = url.replace("/","_");
url = url.replace("/","_");
url = url.replace("/","_");
url = url.replace("/","_");
url = url.replace("/","_");
url = url.replace("/","_");
url = url.replace("/","_");
url = url.replace(" ","_");
url = url.replace(" ","_");
url = url.replace(" ","_");
url = url.replace(" ","_");
return url;
}


//var subwebs;
var selectedweb ="",currentweburl="";
function GetallWebs( relurl){
currentweburl = relurl;
selectedweb = replacespecialitems(relurl);
 //var CurrentclientContext = SP.ClientContext.get_current(relurl);
  var CurrentclientContext =  new SP.ClientContext(relurl);
 this.subwebs =  CurrentclientContext.get_web().get_webs();

 CurrentclientContext.load(this.subwebs);
 CurrentclientContext.executeQueryAsync(Function.createDelegate(this, this.onSubWebsLoaded), Function.createDelegate(this, this.onQueryFailed));
}

function onSubWebsLoaded(){
var count = this.subwebs.get_count();
if(count > 0){
 jQuery( "#"+selectedweb).append("<ul id='"+selectedweb+"sub'></ul>>");
 for (var i = 0; i < this.subwebs.get_count(); i++){
 var subtitle =  this.subwebs.itemAt(i).get_title();
 var subsiteurl =  this.subwebs.itemAt(i).get_url();

 jQuery( "#"+selectedweb+"sub").append("<li><a href='/_layouts/Deletesite.aspx'>" +subtitle +"</a>  <a>"+subsiteurl +"</a>&nbsp;&nbsp; &nbsp;&nbsp;<span><a id='delete' href='javascript:;' onclick='javascript:DeleteSubWeb(&quot;"+subsiteurl+"&quot; )'> Delete Web </a></span></li>");
}
}
else{
currentweburl
 jQuery("#noSub"+selectedweb).append("<a onclick='javascript:DeleteSubWeb(&quot;"+currentweburl+"&quot; )'> Delete this web </a>");
}
currentweburl="";
selectedweb="";
}

function DeleteSubWeb(loc){
var clientContext = new SP.ClientContext(loc);
var oweb = clientContext.get_web();
oweb.deleteObject();
clientContext.executeQueryAsync(Function.createDelegate(this, this.onSubWebDeleted), Function.createDelegate(this, this.onQueryFailed));
}
function onSubWebDeleted(){
console.log("Web deleted successfully.");
}

ExecuteOrDelayUntilScriptLoaded(loadWebs, "sp.js");

</script>
<div>
<ul id="data">
</ul>
</div>

Monday 9 December 2013

Sharepoint  urls

Here's the URL: http://<your site collection URL>/_catalogs/users/simple.aspx

list of webparts
 /_catalogs/wp/Forms/AllItems.aspx


User groups 
_layouts/groups.aspx

 Sitemanager page to manage pagelayouts
_layouts/sitemanager.aspx

Delete current web 
_layouts/Deleteweb.aspx


save current site as template
_layouts/savetmpl.aspx


to show site contents
_layouts/viewlsts.aspx

to see webparts and contents in side a pge

/pages/pagename.aspx?contents=1

to edit the page using url

/pages/pagename.aspx?displaymode=design

settings page

_layouts/settings.aspx



user profiles list(should be admin)

/_catalogs/users/simple.aspx



Get the version of the SharePoint server (Patch level): thanks to John
 /_vti_pvt/Service.cnf

Application page for registering SharePoint apps
/_layouts/15/appregnew.aspx

Save Site as a template
/_layouts/savetmpl.aspx

Sign in as a different user
/_layouts/closeConnection.aspx?loginasanotheruser=true

Enable SharePoint designer
/_layouts/SharePointDesignerSettings.aspx

Welcome Page (Default page settings)
/_layouts/AreaWelcomePage.aspx

Change Site Master Page
/_layouts/ChangeSiteMasterPage.aspx

Page Layouts and Site Templates
/_Layouts/AreaTemplateSettings.aspx

Master Pages library
/_catalogs/masterpage/Forms/AllItems.aspx

User Information List
_catalogs/users/simple.aspx

Quick Deploy List
Quick%20Deploy%20Items/AllItems.aspx
 
Open Page in Edit Mode
?ToolPaneView=2

Taxonomy Hidden List (MMS)
Lists/TaxonomyHiddenList/AllItems.aspx

User Information List:
_catalogs/users/simple.aspx

Force displaying the user profile in the site
collection:
/_layouts/userdisp.aspx?id={UserID}&Force=True

Web Part Maintenance Page 
?Contents=1

Show Page in Dialog View
?isdlg=1




in ie 11 if 
‘L_Menu_BaseUrl’ is undefined
‘L_Menu_LCID’ is undefined

use on top of the script 
if(typeof _spPageContextInfo !== "undefined" && _spPageContextInfo.webUIVersion === 15){
 var L_Menu_BaseUrl = L_Menu_BaseUrl || _spPageContextInfo.webServerRelativeUrl !== "/" ? _spPageContextInfo.webServerRelativeUrl : "";
 var L_Menu_LCID = L_Menu_LCID || _spPageContextInfo.currentLanguage.toString();
}
Important Note:
In SPServices Data will return from the default view of the list or library if your are not providing any view.

ECB Menu in gridview

http://code.msdn.microsoft.com/office/Ejemplos-sobre-cmo-usar-el-69cd5f16

window.onbeforeunload = function(){
console.log(window.location.toString());
            return 'Are you sure you want to leave?';
        };


Sharepoint 2013 title column navigation to custom page.



<script type="text/javascript">
$(function() {
  // Change all display form links to edit form links
  $
('.ms-vb a[href*="listform.aspx"]').each(function(){
      
var link = $(this).attr('href');
      link 
= link.replace("PageType=4", "PageType=6");
      $
(this).attr('href', link);  // use your custom url here
  });
});
</script>

sharepoint 2013 application page while using javascript client object model added script link tags.

when used onDeman=true my code started working.

 <SharePoint:ScriptLink ID="ScriptLink1" language="javascript"  OnDemand="true" Name="SP.js" defer="true" runat="server" Localizable="false"/>
    <SharePoint:ScriptLink ID="ScriptLink2" language="javascript" name="SP.Debug.js" defer="true" runat="server" Localizable="false"/>
    <SharePoint:ScriptLink ID="ScriptLink3" language="javascript"  OnDemand="true" Name="SP.Runtime.Debug.js" defer="true" runat="server" Localizable="false"/>
    <SharePoint:ScriptLink ID="ScriptLink4" language="javascript"  OnDemand="true" Name="SP.core.js" defer="true" runat="server" Localizable="false"/>
    

Monday 28 October 2013

Get root site url using CSOM

var clientContext = new SP.ClientContext();
var owebsite = clientContext.get_site.get_rootWeb();
Without client object model you can use the following
var siteCollectionPath= _spPageContextInfo.siteServerRelativeUrl;

Friday 25 October 2013

SharePoint  Field validation for special characters.
Friday, October 25, 2013
8:42 PM

can be used in single field or entire list validation




=AND(IF(ISERROR(FIND(",",Title)),TRUE),IF(ISERROR(FIND("&",Title)),TRUE),IF(ISERROR(FIND("!",Title)),TRUE),IF(ISERROR(FIND("@",Title)),TRUE),IF(ISERROR(FIND("~",Title)),TRUE),IF(ISERROR(FIND("#",Title)),TRUE),IF(ISERROR(FIND("$",Title)),TRUE),IF(ISERROR(FIND("%",Title)),TRUE),IF(ISERROR(FIND("^",Title)),TRUE),IF(ISERROR(FIND("*",Title)),TRUE),IF(ISERROR(FIND("(",Title)),TRUE),IF(ISERROR(FIND(")",Title)),TRUE),IF(ISERROR(FIND("-",Title)),TRUE),IF(ISERROR(FIND("=",Title)),TRUE),IF(ISERROR(FIND("+",Title)),TRUE),IF(ISERROR(FIND(":",Title)),TRUE),IF(ISERROR(FIND(";",Title)),TRUE),IF(ISERROR(FIND("<",Title)),TRUE),IF(ISERROR(FIND(">",Title)),TRUE),IF(ISERROR(FIND("?",Title)),TRUE),IF(ISERROR(FIND("'",Title)),TRUE),IF(ISERROR(FIND("{",Title)),TRUE),IF(ISERROR(FIND("}",Title)),TRUE),IF(ISERROR(FIND("[",Title)),TRUE),IF(ISERROR(FIND("]",Title)),TRUE),IF(ISERROR(FIND(".",Title)),TRUE),IF(ISERROR(FIND("/",Title)),TRUE),IF(ISERROR(FIND("\",Title)),TRUE),IF(ISERROR(FIND("""",Title)),TRUE))

Monday 21 October 2013

Check current user permissions using jsom

function checkifUserHasEditPermissions() {
context = new SP.ClientContext.get_current();
web = context.get_web();
this._currentUser = web.get_currentUser();
context.load(this._currentUser);
context.load(web,'EffectiveBasePermissions');
context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod));
}
function onSuccessMethod(sender, args) 
{
if (web.get_effectiveBasePermissions().has(SP.PermissionKind.editListItems)) 
{
//User Has Edit Permissions
}
}}

Sunday 6 October 2013

Check if file exist using script.

1)
same domain this should work:
function UrlExists(url)
{
    var http = new XMLHttpRequest();
    http.open('HEAD', url, false);
    http.send();
    return http.status!=404;
}


or

function fileExists(url) {
    if(url){
        var req = new XMLHttpRequest();
        req.open('GET', url, false);
        req.send();
        return req.status==200;
    } else {
        return false;
    }
}



2)
function ImageExist(url)
{
   var img = new Image();
   img.src = url;
   return img.height != 0;
}

3)
<img src="image.gif" onerror="imgError()" />

4)
$.get(url)
    .done(function() { 
        // exists code 
    }).fail(function() { 
        // not exists code
    })

5)

$.ajax({
    url:'http://www.example.com/somefile.ext',
    type:'HEAD',
    error: function()
    {
        //file not exists
    },
    success: function()
    {
        //file exists
    }
});
For a client computer this can be achieved by:
try
{
  var myObject, f;
  myObject = new ActiveXObject("Scripting.FileSystemObject");
  f =   myObject.GetFile("C:\\img.txt");
  f.Move("E:\\jarvis\\Images\\");
}
catch(err)
{
  alert("file does not exist")
}
6)Image exists. 
function checkImage(src) {
  var img = new Image();
  img.onload = function() {
      // code to set the src on success
      $('#image-test').css('background', 'url(' + src + ') no-repeat 50% 50%');
  };
  img.onerror = function() {
    // doesn't exist or error loading
    alert('no image');
  };

  img.src = src; // fires off loading of image
}

checkImage('http://www.google.com/images/logo_sm.gif');



Saturday 28 September 2013

Get List Items Using JSOM


 var Title = "Document Sharing";
var CurrentFolderItems;
    function GetListItems() {
 
        var clientContext = new SP.ClientContext.get_current();
        var oWeb = clientContext.get_web();
        var currentTabList = this.oWeb.get_lists().getByTitle("Budgets");
        var query = new SP.CamlQuery();      
        var querytext = '<View><Query><Where><Neq><FieldRef Name="Title" /><Value Type="Text">0</Value></Neq></Where></Query></View>';
        query.set_viewXml(querytext);
        CurrentFolderItems = currentTabList.getItems(query);
        clientContext.load(CurrentFolderItems);
        clientContext.executeQueryAsync(
Function.createDelegate(this, this.onQueryGetFolderItemsSucceded),
        Function.createDelegate(this, this.onQueryGetFolderItemsFailed));

    }

    function onQueryGetFolderItemsSucceded() {

console.log("1");
   var data="";
    var ListEnumerator = this.CurrentFolderItems.getEnumerator();
while(ListEnumerator.moveNext()){
    var item = ListEnumerator.get_current();

   var image = item.get_item("Title");
   var itemimg = item.get_path("Image");

   for(i in itemimg )
   {
   console.log(itemimg[i]);// data += item[i];
   }
  data += "\n"+image+ itemimg;  
    }
alert(data);
}

function onQueryGetFolderItemsFailed(sender,args){
console.log(args.get_message());
}

GetListItems();

Thursday 26 September 2013



 Generally, a SharePoint Administrator can be either: 
  • A Server-centric SharePoint Administrator - This person deals with everything that takes place within the cozy little area that we call the server closet.  None of this person's interaction with SharePoint will be through a web browser with the exception of Central Administration tasks.  This would be more akin to the system administrator or server administrator function.  His necessary skills might also include familiarity with networking, hardware, host OS, SQL admin, etc. -- the difference being that the strength of this individual is the manipulation of the systems that provide the SharePoint services.  Though it is useful for these administrators to be familiar with SharePoint's user interface and functionality, it may not be entirely necessary, depending on the specific nature of their duties. 
  • A User-centric SharePoint Administrator - The man or woman in the trenches -- SharePoint administration on the front line.  This individual would interact with users and interact with SharePoint almost exclusively through a web browser.  He or she might need to use Central Administration occasionally depending on his/her specific duties.  This person would go to a Server-centric administrator for anything involving the mechanics under the hood.  The rights to the SharePoint site or Site Collection may be unlimited or restricted to specific roles.  Any individual that does more than view or add content would probably fall into this category.  Creating a list or library or even setting basic permissions on an item would qualify as a User-centric Administrator function.
 
These lines are obviously not hard, solid, and impermeable.  Depending on the business needs, the gray area of delineation between the two will probably be constantly changing.  So why is this distinction important at all?  That's what prompted this blog post.  With Microsoft's push to provide hosted services, the lines have become a little more necessary when looking for training.  With Office 365 SharePoint, an online SharePoint solution hosted by Microsoft, the Server-centric administration is all handled by Microsoft.  The back end is almost totally off limits to "administrators" with good reason.  This frees up businesses from having to invest in Server-centric expertise.  It then leaves a business with a need for User-centric expertise.  This is the diverging point. 

An individual called the other day and declared that he had been made the Office 365 SharePoint administrator.  Their question was "What course within SharePoint Solutions' offerings should I take for this position?"  In this circumstance, the most beneficial course would be one of our introductory courses.  Since the Office 365 SharePoint environment is almost entirely user-centric, then the best way to get in and administer it would be to learn exactly what users do with SharePoint.  In a sense, one could say that a User-centric SharePoint Administrator is a "super-user".  But this term would downplay the level of skill required for a User-centric administrator to set up lists and libraries, not to mention setting up a structure that would allow users to set up lists and libraries.

The term "SharePoint Administrator" is simply too vague to be useful in and of itself.  The term needs to be clarified by what the Administrator will be administering.  With this clarification, the most appropriate path, and course, may be chosen to take your SharePoint skills to the next level.





1. Create a JavaScript file and put it in directory under the root project’s directory:
2. Open the properties of the JavaScript file. Under “Build Action” select “Embedded Resource”.
3. In the “AssemblyInfo.cs” add this line:
[assembly: System.Web.UI.WebResource("[Assembly Name].[Folder].[JS file]", "text/javascript")]
For Example, in my project:
[assembly:
System.Web.UI.WebResource("XXX.WebPart.ListViewer.Script.ListViewer.js", "text/javascript")]

4. Add this line in the constractor of your control / web-part:this.PreRender += new EventHandler(MyControl_PreRender);

5. Add these 2 lines in the Pre_Render event of your web-part:string jsLocation = Page.ClientScript.GetWebResourceUrl(this.GetType(), "[Assembly Name].[Folder].[JS File]");
Page.ClientScript.RegisterClientScriptInclude("MyScript", jsLocation);