Tuesday, 30 December 2014

Get UserInformation/ Site Information Using client side script

Recently I have to display client info on a page. I have two options, either with webpart (server side control) or  use script editor webpart (client object modal).

Here is the script i use:

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script type="text/javascript">
  var userid= _spPageContextInfo.userId;
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + userid + ")";
var requestHeaders = { "accept" : "application/json;odata=verbose" };
$.ajax({
    url : requestUri,
    contentType : "application/json;odata=verbose",
    headers : requestHeaders,
    success : onSuccess,
    error : onError
});

function onSuccess(data, request){
    var Logg = data.d;    
document.getElementById('welcomediv').innerHTML="Hello, "+Logg.Title;
document.getElementsByTagName('title')[0].innerHTML='Home';  
}
function onError(error) {
    alert("error");
}
</script>


If you want Site Name, Here is the code:

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () { SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getWebProperties); $('.userprofilpic').hide();});
    function getWebProperties() {
        var ctx = new SP.ClientContext.get_current();
        this.web = ctx.get_web();
       ctx.load(this.web,'Title');
        ctx.executeQueryAsync(Function.createDelegate(this, this.onSuccess),
            Function.createDelegate(this, this.onFail));
    }
    function onSuccess(sender, args) {
document.getElementById('welcomediv').innerHTML="Site Name: "+this.web.get_title();    
    }
    function onFail(sender, args) {
        alert('failed to get list. Error:'+args.get_message());
    }
</script>

That's it for now.

Wednesday, 3 December 2014

"Sign in as Different User" in SharePoint 2013

One of features used in testing of permissions in SharePoint is "Sign in as Different User" which allows you to log in as an another user.  With SharePoint 2013 this option is missing.

To get this feature back follow the following steps :

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.

Thursday, 27 November 2014

Get Site Template GUID using Powershell

Sometimes we need to find the GUID of save site template.

Open Power shell management shell in administrator mode.
 here is the power shell script that provide you the functionality. pate it.

 $url = "http://localhost:mysite/"

$site= new-Object Microsoft.SharePoint.SPSite($url )

$loc= [System.Int32]::Parse(1033)

$templates= $site.GetWebTemplates($loc)

foreach ($child in $templates){ write-host $child.Name "  " $child.Title}

click Enter. And you will get the list of site template with the GUID.
Enjoy

Friday, 21 November 2014

How to delete the unused application pool From IIS?

Recently I had issue with user profile service. I delete it and try to recreate it. That time I got an error
"
An object of the type Microsoft.SharePoint.Administration.SPIisWebServiceApplicationPool named "User Profile Service App Pool" already exists under the parent Microsoft.SharePoint.Administration.SPIisWebServiceSettings named "SharePoint Web Services".  Rename your object or delete the existing object.
".

So I search for the resolution of the issue. I got two options
1. They say Try a  different name. - Which didn't help in my case.I would say try your luck also.
2. Delete current app pool and try again to create.

So here is the process:

IIS will not provide the interface for managing service application's application pools. But we can delete service application's application pool in SharePoint 2010/2013  using powershell.

Use these below cmd-let to get list of service application's application pools.
Get-SPServiceApplicationPool

SharePoint 2010/2013 delete orphaned application pool: To delete a application pool of service application, use the cmdlet:
Remove-SPServiceApplicationPool

 1. Run "Sharepoint Management Shell " in administrator mode.
 2. Type "Get-SPServiceApplicationPool". It will give you list of app pool.
 3. Type "Remove-SPServiceApplicationPool". 
 4. It will ask you identity. Give the app pool name you want to remove from above list. Try not to make  spell mistake.
 5. Click Enter.
 6.It will ask for confirmation. Type "y". click Enter.
Enjoy.
 




Thursday, 20 November 2014

Linq query to datatable conversion

Recently I have encounter with Linq after a long time and I was required to convert linq result in to datatable. It take a while but I found the method i used in past. I hope it will help you too.

 1. use AsEnumerable() in your query.and you will be good to get a function CopyToDataTable() to get datatable.
  Example:
var query =
    from order in orders.AsEnumerable()
    join detail in details.AsEnumerable()
    on order.Field<int>("SalesOrderID") equals
        detail.Field<int>("SalesOrderID")
    where order.Field<bool>("OnlineOrderFlag") == true
    && order.Field<DateTime>("OrderDate").Month == 8
    select new
    {
        SalesOrderID =
            order.Field<int>("SalesOrderID"),
        SalesOrderDetailID =
            detail.Field<int>("SalesOrderDetailID"),
        OrderDate =
            order.Field<DateTime>("OrderDate"),
        ProductID =
            detail.Field<int>("ProductID")
    };

DataTable orderTable = query.CopyToDataTable(); 
 
Original Source : http://msdn.microsoft.com/en-us/library/bb386921%28v=vs.110%29.aspx

2. use this coustom method to get datatable

 Example:
public DataTable ToDataTable(System.Data.Linq.DataContext ctx, object query)
{
     if (query == null)
     {
          throw new ArgumentNullException("query");
     }
    
     IDbCommand cmd = ctx.GetCommand(query as IQueryable);
     SqlDataAdapter adapter = new SqlDataAdapter();
     adapter.SelectCommand = (SqlCommand)cmd;
     DataTable dt = new DataTable("sd");

     try
     {
          cmd.Connection.Open();
          adapter.FillSchema(dt, SchemaType.Source);
          adapter.Fill(dt);
     }
     finally
     {
          cmd.Connection.Close();
     }
     return dt;
}

For getting datatable

var vr = from country in objDataContext.CountryMaster
                        select new {country.CID,country.CName};

DataTable dt = ToDataTable(objDataContext,vr);

Original source : http://www.c-sharpcorner.com/uploadfile/VIMAL.LAKHERA/convert-a-linq-query-resultset-to-a-datatable/

Monday, 17 November 2014

On-screen Keyboard in Windows

Sometimes soon we will have a touchscreen desktops in our work premises. If you want a on screen keyboard here are some shortcuts

1.
Click the Start menu, point to All Programs, point to Accessories, point to Accessibility, and then click On-Screen Keyboard to open On-Screen Keyboard.
(link - http://windows.microsoft.com/en-IN/windows-xp/help/on-screen-keyboard)

 2. My way start -> run -> type "osk". click ok. you can create shortcut on desktop writing osk in shotcut. and click on it.

Enjoy.

Monday, 6 October 2014

Free Operating Systems

Worried about licence OS?

Feel free of licence Microsoft OS and use this Linux based operating systems.
I have some free os name and their sites where you can download it.

No 5 PC-BSD9 : HTTP://www.pcbsd.org/
No 4 ArchBang Linux : HTTP://archbang.org/
No 3 Zorin OS 5 : HTTP://zorin-os.com/index.html
No 2 CrunchBang : HTTP://crunchbanglinux.org/
No 1 Puppy Linux : HTTP://puppylinux.org
No 0 startos: HTTP://www.startos.org/

Enjoy.

Tuesday, 30 September 2014

Play any video in HTML in IE.

"Play any kind of video ".
I was working on IE-8. Here is the code I use to integrate video in my page.
Example:

<html>
<body>
<link href="//releases.flowplayer.org/5.5.0/skin/minimalist.css" rel="stylesheet"></link>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//releases.flowplayer.org/5.5.0/flowplayer.min.js"></script>
<div class="flowplayer">
   <video>
      <source src="http://www.W3Schools.com/tags/movie.mp4" type="video/mp4"></source>
   </video>
</div>
</body>
</html>

Friday, 12 September 2014

Error occurred in deployment step 'Retract Solution': The language-neutral solution package was not found.

I was working on one project when i got this error while deployment and i have Google it. I found some solution which are as below


  1. Close Visual Studio Solution and completely exit out of it, then run it again and compile. This sometimes fixes the issue. 
  2. Right-Click on your Visual Studio Solution, select "Clean" Solution, then Right Click on SharePoint Project and choose "Retract". Rebuild and Deploy. 
  3. In PowerShell running as Administrator run Uninstall-SPSolution: 
  4. Unistall-SPSolution -identity {Name of WSP File} -allwebapplications
  5. In PowerShell running as Administrator run Remove-SPSolution:                                   Remove-SPSolution -identity {Name of WSP File} -force
  6. In PowerShell running as Administrator run the Delete() command:                                     (Get-SPSolution {Name of WSP File}).Delete() 


But In My problem I do not Find WSP to uninstall. so what to do in such condition:
Just Follow this step:
  1. Open Your solution and Publish the Project. This will create wsp in Bin folder of your project.
  2. Open cmd in Administrator mode and enter this path;  cd C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN\
  3. Then type following command to add wsp : stsadm -o addsolution -filename <path of .wsp file>.
  4. Then type following command to add wsp : stsadm -o deploysolution -name <name of .wsp file> -url  <site url>  - immediate -allowgacdeployment -force.

this work for me. when i deploy again it run as smoothly as it could.  

Thursday, 11 September 2014

javascript keypress event

Sometimes we need to handle enter key event on textbox. For that we can use fiollowing code

    $('#myInput').keypress(function(event) {
        if (event.keyCode == 13) {
            alert('Entered'); // write your code here
        }
    });

myInput : textbox/ input control id
event.keyCode : The e key value you needed.
Here are some key values:
Key Code
backspace 8
tab 9
enter 13
shift 16
ctrl 17
alt 18
pause/break 19
caps lock 20
escape 27
page up 33
page down 34
end 35
home 36
left arrow 37
up arrow 38
right arrow 39
down arrow 40
insert 45
delete 46
0 48
1 49
2 50
3 51
4 52
5 53
6 54
7 55
8 56
9 57
a 65
b 66
c 67
d 68
Key Code
e 69
f 70
g 71
h 72
i 73
j 74
k 75
l 76
m 77
n 78
o 79
p 80
q 81
r 82
s 83
t 84
u 85
v 86
w 87
x 88
y 89
z 90
left window key 91
right window key 92
select key 93
numpad 0 96
numpad 1 97
numpad 2 98
numpad 3 99
numpad 4 100
numpad 5 101
numpad 6 102
numpad 7 103
Key Code
numpad 8 104
numpad 9 105
multiply 106
add 107
subtract 109
decimal point 110
divide 111
f1 112
f2 113
f3 114
f4 115
f5 116
f6 117
f7 118
f8 119
f9 120
f10 121
f11 122
f12 123
num lock 144
scroll lock 145
semi-colon 186
equal sign 187
comma 188
dash 189
period 190
forward slash 191
grave accent 192
open bracket 219
back slash 220
close braket 221
single quote 222

SharePoint Classic Site Retirement: Your Plan to Avoid Last-Minute Chaos

Classic SharePoint has been on borrowed time for years. Microsoft has now put dates on the remaining pieces. Microsoft will disable creation...