Windows PowerShell is a fantastic tool; SharePoint 2010 has literally hundreds of different PowerShell Cmdlets that are available out of the box,
if you don’t believe me check this out - http://technet.microsoft.com/en-us/library/ff678226.aspx. What about MOSS 2007? Whilst there aren’t any native Cmdlets for MOSS 2007, PowerShell can be used to access the SharePoint object model directly instead and in most cases achieve the same objectives, this isn’t as daunting as it sounds.
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
#Configure the location for the output file
$Output="C:\amar\Output.csv";
"Site URL"+","+"Owner Login"+","+"Owner Email"+","+"Root Site Last Modified"+","+"Quota Limit (MB)"+","+"Total Storage Used (MB)"+","+"Site Quota Percentage Used" | Out-File -Encoding Default -FilePath $Output;
#Specify the root site collection within the Web app
$Siteurl="http://370dw7e07621";
$Rootweb=New-Object Microsoft.Sharepoint.Spsite($Siteurl);
$Webapp=$Rootweb.Webapplication;
#Loops through each site collection within the Web app, if the owner has an e-mail address this is written to the output file
Foreach ($Site in $Webapp.Sites)
{
if ($Site.Quota.Storagemaximumlevel -gt 0)
{
[int]$MaxStorage=$Site.Quota.StorageMaximumLevel /1MB
}
else {$MaxStorage="0"};
if ($Site.Usage.Storage -gt 0)
{
[int]$StorageUsed=$Site.Usage.Storage /1MB
};
if ($Storageused-gt 0 -and $Maxstorage-gt 0)
{
[int]$SiteQuotaUsed=$Storageused/$Maxstorage* 100}
else
{ $SiteQuotaUsed="0" };
$Web=$Site.Rootweb; $Site.Url + "," + $Site.Owner.Name + "," + $Site.Owner.Email + "," +$Web.LastItemModifiedDate.ToShortDateString() + "," +$MaxStorage+","+$StorageUsed + "," + $SiteQuotaUsed | Out-File -Encoding Default -Append -FilePath $Output;$Site.Dispose()};
Wednesday, April 23, 2014
Interating with DOM (Jquery)
Interacting with DOM :
Iterating through Nodes,
Modifying Dom Object
Modifying Attributes
Adding and removing Nodes
Modifying Styles
Modifying Classes
Iterating Through Nodes :
.each(function(index,Element)) is used to iterate through
Jquery Object.
$(‘div’).each(function(index)
{Alert(index+ ’=’ +$(this).text());
});
Iterates through each div element and returns its index
number and text.
$(‘div’).each(function(index,elem)
{Alert(index+ ’=’ +$(elem).text());
});
Elem = this
Example :
Div id are blueDIv
and RedDiv
$(documents).ready(function(){
Var output= $(‘#outputDIv);
$(‘div.bluediv,div.reddiv’).each(function
(index)
{
Output.html(output.html()+”</br>”
+ index+ “ ” + $(this).text())}
});
This means raw DOM object
Modifying DOM Objects Properties :
The This.PropertyName statement can be used to modify
an object’s Properties directly:
$(‘div).each(function(i)
{ This.title=”my Index=” +i;
});
Iterates through each div and
modifies the title. If the property does not exist ,it will be added.
Modifying Multiple
Attributes :
TO modify multiple
attributes, Pass a JSON Object
containing Name/Value Pairs : All the image |
$(‘img’).attr ({
Title: ‘My Image
Title;,
Style:’border:2px
solid back;’
});
Json Object passed and used
to change title and border
Modifying Attributes :
Objecct attribures can be
accessed using attr();
Var
val=$(‘#CustomerDiv’).attr(‘title’);
Retrieves the values of the
Title attribute :
.attr(attributeName,Value) is the
method used to access an object attributes modify the value:
$(‘img’).attr(‘title’,’My
Image Title’);
Change the title attribute to
a value of my image Title.
Whats, Json :
JSON Delimits object
using {
and }
The :
character separates properties and values {
FirstName :
‘jhon’,
LastName : ‘Doe’,Address : // THis is nested Json object
{
Street : ‘1234 anywhere st ,’,
City : ‘GA’,State : ‘AX’
Zipcode : 85675
}
}
Four key methods handle
inserting nodes into elements:
.append()
.appenTo().prepend()
.prependTo()
To remove node from an
element use . Remove()
$(‘<Span>
(office) </span>’).appendTo(‘.officePhone’);
Or
$(‘.officePhone’).append(‘<span>(office)</span>’);
Would result in (office)
being added into each .officephone class element
Wrapping Elements :
<div class=”State”>
Arizona<div>
$(‘.state’).wrap(‘<div
class=”US_State” />’);
Result:
<div class=”US_State”>
<div class=”State”>Arizona </div>
</div>
.remove :
$(‘.phone,.location’).remove();
Modifying Styles :
The .css() function can be used to modify an object’s
style :
$(“div”).css(“color”,”red”);
All the DIVs
Multiple styles can be
modified by passing a JSON object :
$(‘div’).css(
{
‘color’:’#ccff’,
‘font-weight’:bold’
});
Modifying Classes :
The four methods for working
with CSS class attributes are :
.addClass()
.hasClass()
.removeClass()
.toggleClass()
Example :
$(‘p’).addClass(‘ClassOne’);
More than once
class :
$(‘p’).addclass(‘classOne ClassTwo’);
.hasClass() return true if the selected element has a matching
class that is specified :
If($(‘p’).hasClass(‘styleSpecifi’))
{
// perform work
}
.removeCLass() can remove one
or more classes :
Remove all class attribures
for the matching selector
$(‘p’).removeclass();
Toggling CSS Classes
:
.toggleClass() alternates adding or removing a class based on the
current presence or absence of the class
$(‘#phoneDetails’).toggleClass(‘highlight’);
<style type=”text\css”>
.highlight { background:yellow; }
</style>
Example :
$(‘input[type=’text’]’).addclass(Highlight);
Example ( Text allows only charters)
HTML :
Number : <input type="text" name="quantity" id="quantity" />
phone : <input type="text" name="namePhone" id="idphone"/>
<span id="errmsg">
</span>
Jquery
$(document).ready(function () {
//called when key is pressed in textbox
$("#quantity ,#idphone").keypress(function (e) {
//if the letter is not digit then display error and don't type anything
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
//display error message
$("#errmsg").html("Digits Only").show().fadeOut("slow");
return false;
}
});
});
CSS :
#errmsg
{
color: red;
}
Example ( Text allows only charters)
HTML :
Number : <input type="text" name="quantity" id="quantity" />
phone : <input type="text" name="namePhone" id="idphone"/>
<span id="errmsg">
</span>
Jquery
$(document).ready(function () {
//called when key is pressed in textbox
$("#quantity ,#idphone").keypress(function (e) {
//if the letter is not digit then display error and don't type anything
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
//display error message
$("#errmsg").html("Digits Only").show().fadeOut("slow");
return false;
}
});
});
CSS :
#errmsg
{
color: red;
}
Tuesday, April 15, 2014
Finding and Installing a NuGet Package Using the Package Manager Console
This topic describes how to find, install, remove, and update NuGet packages using PowerShell commands. You can also work with packages using the Manage NuGet Packages dialog box. For more information, see [Using the Manage NuGet Packages dialog](Using-the Add-Library-Package-Reference-Dialog-Box).
Using PowerShell commands is required if you want to install a package without having a solution open. It's also required in some cases for packages that create commands that you can access only by using PowerShell.
, select
The two drop-down lists set default values that let you omit parameters from the commands you enter in the window:
Example :
Get-Package -ListAvailable ( This will return all the packages)
Get-Package -Filter Jquery -ListAvailable (This will return jquery available packages)
Install-Package Jquery << ProjectName>>
Refer the below screen for more information:
Using PowerShell commands is required if you want to install a package without having a solution open. It's also required in some cases for packages that create commands that you can access only by using PowerShell.
Finding a Package
From the Tools menuLibrary Package Manager and then click Package Manager Console., select
The two drop-down lists set default values that let you omit parameters from the commands you enter in the window:
- In the Package source list, select the default source (NuGet package feed) that you want your commands to use. Typically you will leave this as its default value of NuGet official package source. For more information about alternative feeds, see Hosting Your Own NuGet Feeds.
- In the Default project list, select the default project that you want your commands to work with. (The default value will be the first project in the solution, not necessarily the one you have selected in Solution Explorer when you open the window.)
Get-Package -ListAvailable at the prompt to see a list of all packages that are available in the selected package source.Example :
Get-Package -ListAvailable ( This will return all the packages)
Get-Package -Filter Jquery -ListAvailable (This will return jquery available packages)
Install-Package Jquery << ProjectName>>
Refer the below screen for more information:
Thursday, February 20, 2014
Create, Update, and Delete List Items using C O M
Creating Items:
To create list items, you create a ListItemCreationInformation object, set its properties, and pass it as parameter to the AddItem(ListItemCreationInformation) method of the List class. Set properties on the list item object that this method returns, and then call the Update() method, as seen in the following example.
using System;
using Microsoft.SharePoint.Client;
using SP = Microsoft.SharePoint.Client;
namespace Microsoft.SDK.SharePointServices.Samples
{
class CreateListItem
{
static void Main()
{
string siteUrl = "http://MyServer/sites/MySiteCollection";
ClientContext clientContext = new ClientContext(siteUrl);
SP.List oList = clientContext.Web.Lists.GetByTitle("Announcements");
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem oListItem = oList.AddItem(itemCreateInfo);
oListItem["Title"] = "My New Item!";
oListItem["Body"] = "Hello World!";
oListItem.Update();
clientContext.ExecuteQuery();
}
}
}
Updating a list item
To set most list item properties, you can use a column indexer to make an assignment, and call the Update() method so that changes will take effect when you call ExecuteQuery() or ExecuteQueryAsync(ClientRequestSucceededEventHandler, ClientRequestFailedEventHandler). The following example sets the title of the third item in the Announcements list.
using System;
using Microsoft.SharePoint.Client;
using SP = Microsoft.SharePoint.Client;
namespace Microsoft.SDK.SharePointServices.Samples
{
class UpdateListItem
{
static void Main()
{
string siteUrl = "http://MyServer/sites/MySiteCollection";
ClientContext clientContext = new ClientContext(siteUrl);
SP.List oList = clientContext.Web.Lists.GetByTitle("Announcements");
ListItem oListItem = oList.Items.GetById(3);
oListItem["Title"] = "My Updated Title.";
oListItem.Update();
clientContext.ExecuteQuery();
}
}
}
Deleting Items from List
To delete a list item, call the DeleteObject() method on the object. The following example uses the GetItemById() method to return the second item from the list, and then deletes the item.
SharePoint Foundation 2010 maintains the integer IDs of items within collections, even if they have been deleted. So, for example, the second item in a list might not have 2 as its identifier. A ServerException is returned if the DeleteObject() method is called for an item that does not exist.
using System;
using Microsoft.SharePoint.Client;
using SP = Microsoft.SharePoint.Client;
namespace Microsoft.SDK.SharePointServices.Samples
{
class DeleteListItem
{
static void Main()
{
string siteUrl = "http://MyServer/sites/MySiteCollection";
ClientContext clientContext = new ClientContext(siteUrl);
SP.List oList = clientContext.Web.Lists.GetByTitle("Announcements");
ListItem oListItem = oList.GetItemById(2);
oListItem.DeleteObject();
clientContext.ExecuteQuery();
}
}
}
To create list items, you create a ListItemCreationInformation object, set its properties, and pass it as parameter to the AddItem(ListItemCreationInformation) method of the List class. Set properties on the list item object that this method returns, and then call the Update() method, as seen in the following example.
using System;
using Microsoft.SharePoint.Client;
using SP = Microsoft.SharePoint.Client;
namespace Microsoft.SDK.SharePointServices.Samples
{
class CreateListItem
{
static void Main()
{
string siteUrl = "http://MyServer/sites/MySiteCollection";
ClientContext clientContext = new ClientContext(siteUrl);
SP.List oList = clientContext.Web.Lists.GetByTitle("Announcements");
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem oListItem = oList.AddItem(itemCreateInfo);
oListItem["Title"] = "My New Item!";
oListItem["Body"] = "Hello World!";
oListItem.Update();
clientContext.ExecuteQuery();
}
}
}
Updating a list item
To set most list item properties, you can use a column indexer to make an assignment, and call the Update() method so that changes will take effect when you call ExecuteQuery() or ExecuteQueryAsync(ClientRequestSucceededEventHandler, ClientRequestFailedEventHandler). The following example sets the title of the third item in the Announcements list.
using System;
using Microsoft.SharePoint.Client;
using SP = Microsoft.SharePoint.Client;
namespace Microsoft.SDK.SharePointServices.Samples
{
class UpdateListItem
{
static void Main()
{
string siteUrl = "http://MyServer/sites/MySiteCollection";
ClientContext clientContext = new ClientContext(siteUrl);
SP.List oList = clientContext.Web.Lists.GetByTitle("Announcements");
ListItem oListItem = oList.Items.GetById(3);
oListItem["Title"] = "My Updated Title.";
oListItem.Update();
clientContext.ExecuteQuery();
}
}
}
Deleting Items from List
To delete a list item, call the DeleteObject() method on the object. The following example uses the GetItemById() method to return the second item from the list, and then deletes the item.
SharePoint Foundation 2010 maintains the integer IDs of items within collections, even if they have been deleted. So, for example, the second item in a list might not have 2 as its identifier. A ServerException is returned if the DeleteObject() method is called for an item that does not exist.
using System;
using Microsoft.SharePoint.Client;
using SP = Microsoft.SharePoint.Client;
namespace Microsoft.SDK.SharePointServices.Samples
{
class DeleteListItem
{
static void Main()
{
string siteUrl = "http://MyServer/sites/MySiteCollection";
ClientContext clientContext = new ClientContext(siteUrl);
SP.List oList = clientContext.Web.Lists.GetByTitle("Announcements");
ListItem oListItem = oList.GetItemById(2);
oListItem.DeleteObject();
clientContext.ExecuteQuery();
}
}
}
Thursday, February 6, 2014
Dlls not deployed to GAC SP 2013 + Visual Stuio 2012
Target frame work in 4.0 and up , Assembly Location is
C:\windows\microsoft.net\assembly\GAC_MSIL
Out Put Location :
GAC in .NET versions 1.0 through 3.5 are remain same.
C:\windows\assembly\GAC_MSIL
Wednesday, February 5, 2014
Error When Deplying Master page in GhostableInLibrary Files
Below is the code form the elements.xml file from the MasterPages module.
Wrong code Snippet :
Correct code snippet :
Wrong code Snippet :
| <?xml version="1.0" encoding="utf-8"?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <Module Name="MasterPages"> <File Path="MasterPages\Portal.master" Url="Portal.master" IgnoreIfAlreadyExists="True" Type="GhostableInLibrary" /> </Module> </Elements> |
Correct code snippet :
| <?xml version="1.0" encoding="utf-8"?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <Module Name="MasterPages" Url="_catalogs/masterpage" List="116"> <File Path="MasterPages\Portal.master" Url="Portal.master" IgnoreIfAlreadyExists="True" Type="GhostableInLibrary" /> </Module> </Elements> |
Thursday, January 23, 2014
Sharepoint 2010 /2013 Host Header Issues
1. Click Run, type regedit then hit the enter.
2. Navigate to Following Location in registry
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0
3. Add New "Multi-String Value with the Name BackConnectionHostNames.
4. Click to modify BackConnectionHostNames
5. Add the Host Header Name
6. Save and Close the Registry.
For more information Refer the below screen.
2. Navigate to Following Location in registry
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0
3. Add New "Multi-String Value with the Name BackConnectionHostNames.
4. Click to modify BackConnectionHostNames
5. Add the Host Header Name
6. Save and Close the Registry.
For more information Refer the below screen.
Subscribe to:
Posts (Atom)


