Tuesday, 5 May 2015

How to start the workflow for an item using PowerShell / C#

In this article we will be seeing how to start a workflow for an item using c# and powershell

Start a workflow using c#

class Program    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("YourSiteURL"))
            {
                using (SPWeb web = site.RootWeb)
                {
                    SPList list = web.Lists["Test"]; 
                    SPListItem item=list.Items[0];
                    SPWorkflowManager manager = site.WorkflowManager;
                    SPWorkflowAssociation association = list.WorkflowAssociations[0];
                    string data = association.AssociationData;
                    SPWorkflow wf = manager.StartWorkflow(item, association, data, true);
                }
            }
        }
    }


Start a workflow using powershell:

$siteURL="http://servername:1111/"
$listName="Test"
$site=Get-Spsite $siteURL
$web=$site.RootWeb
$list=$web.Lists[$listName]
$item=$list.Items[0]
$manager=$site.WorkFlowManager
$association=$list.WorkFlowAssociations[0]
$data=$association.AssociationData
$wf=$manager.StartWorkFlow($item,$association,$data,$true)

Hope this helps!!!!

How to get document library size using PowerShell?

Below is the PowerShell script which will show the size of Particular library:

   [System.reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
    [System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=12.0.0.0,             Culture=neutral, PublicKeyToken=71e9bce111e9429c”)
    [System.Reflection.Assembly]::Load(“Microsoft.SharePoint.Portal, Version=12.0.0.0,   Culture=neutral, PublicKeyToken=71e9bce111e9429c”)


    Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue

    $siteURL = "YourSiteURL" 
    $site = new-object Microsoft.SharePoint.SPSite($siteURL)


    foreach ($web in $site.AllWebs)
    {
     foreach ($list in $web.Lists)
    {

            if($list.BaseType -eq "DocumentLibrary")   
          {

if($list.Title -eq "YourDocumentLibraryTitle")
{
        $listSize = 0
       foreach ($item in $list.items) 
            { 
              $listSize += ($item.file).length
            }
         "Web: "+$web.Title+", Library Name: "+$list.Title+", Size: "+[Math]::Round(($listSize/1KB),2)+"KB"     
}
    }
    }
    }


Hope this helps!!!!

Wednesday, 29 April 2015

Create a Custom Page Layout in SharePoint 2013

This is a Step-by-Step tutorial on how to Create a Custom Page Layout in SharePoint 2013.We will use the new Design Manager to Create a Layout (from an existing one) and then edit it in one of the editors like Notepad.Once the layout is Created and Uploaded to Master Page Gallery, you can edit the generated html file in an editor of your choice and upload it back to the Master Page Gallery.

Before you begin make sure that you have Publishing Feature enabled on your site and you see “Deisgn Manager” under Look and feel.


  1. Navigate to Site Settings -> Design Manager (under look and feel).
  2. Next in Design Manager select “6. Edit Page Layouts” and then “Create a page layout”
  3. Now Create a Custom Page layout using the Article Page Content type.
  4. When the Layout is Created, it gets available in “Edit Page Layouts” list and the “Master Page gallery” of the site.The Layout Page will be in Drafts mode until you publish it as a major version.
  5. Next Edit the New Layout Page and save the Changes.In SharePoint 2013 for every Layout page two files – .aspx and html are created by default.

    For making Changes to the Custom Layout, you need to download the html file of your layout page and make Changes to it.The modified html file is then saved back to the MasterPage Page gallery where the corresponding .aspx file gets updated automatically.
  6. Once you have updated and saved the Layout page, you need to Publish the Layout page as a major version to make it available in Layouts list.
  7. Finally, Create a new Page with your Custom Layout.

Tuesday, 28 April 2015

How to get ULS Logs in SharePoint 2013 (Developer Dashboard)

If you are a SharePoint developer and have ran around SharePoint Admin teams for ULS Logs here is a quick solution for you. You can get the ULS Logs right from the server for any page that you ran through in Developer Dashboard.

Prerequisites – You need to Activate Developer Dashboard using the following Stsadm command.

stsadm -o setproperty -pn developer-dashboard -pv on

Once you have turned ON the developer dashboard you can open it using a small icon next to “Focus on Content”



Once the Developer Dashboard is Open, refresh the SharePoint site page and it will appear in the developer dashboard.



Click on the “ULS Logs” tabs and you will see the fetching message.

Once its done the ULS tab will be displayed with the Logs from the server.

How to set a page as Home Page in SharePoint 2013 site

In this post we will look at options to set a Custom Page as Home Page in SharePoint 2013 site.

Option 1: If you want to set a Custom Page as a Home Page in a typical SharePoint Team site, you can simply do that by Opening the Page and selecting Page tab in ribbon -> Make HomePage button to set this particular page as default Home Page for your site.

Option 2: Another option to set a Custom Page as Home Page in SharePoint 2013 Team site is by using SharePoint Designer 2013. If you have opened or created a Page in SharePoint Designer then you can right click on the page and select the option “Set as Home Page” to set it as a default home page of your SharePoint site.

Option 3: If you are using the Publishing site (or site with publishing feature enabled), you can simply use the old “Welcome Page” link in the Site settings to set the URL of a page this is the desired home page for your SharePoint site.

How to Add\Embed Video to SharePoint 2013 site page

In this post we will look at how to Add or Embed these videos on SharePoint 2013 page.

You can either use the default Video view page that you get when you add the video to SharePoint or you can use the Video embed code to add the video in SharePoint 2013 page.In this post we will look at where to add the embed code.

  1. Create Asset library in SharePoint and upload a Video in it
  2. Navigate to the site library where you added the video and click on video thumbnail.In the view Video page click on the code icon and open embed code page.
  3. Copy the embed code
  4. Now go to the sharepoint page where you display a video
  5. Click on Insert tab to Insert “Script Editor” Webpart.
  6. Next click on Embed Code in Insert Ribbon tab and add the copied Video code to it.


Done.!!

Ref: http://www.learningsharepoint.com/2012/08/05/how-to-add-a-video-to-sharepoint-2013-site/
http://www.learningsharepoint.com/2012/08/05/addembed-video-to-sharepoint-2013-site-page/

How to add a Youtube video in Sharepoint 2013

In SharePoint 2013 admins can now Insert an iframe element into an HTML field like Content editor webpat on a page. This will let users Embed dynamic content from other sites, such as videos or map directions on any SharePoint site page.

Any external domains that will be Inserted in Iframe should be added as approved domains in “HTML Field Security”. By default, certain trusted external domains are already approved for use in iframes.Site collection administrators can customize the field security settings by changing the default trusted external domains.

To add a Youtube Video add the “Youtube.com” Domain in “HTML Field Security” first. Lets look at the Steps-

  1. Navigate to Site Settings (top-level Site collection) -> HTML Field Security.
  2. Make sure the domain “Youtube.com” is added as permitted domain
  3. Navigate to your Youtube video and click on Share and then Embed. Copy the code from youtube
  4. Add a Content editor webpart on a page and then click on “Edit Source” in “Format Text” tab in Ribbon. Add copied code in the source
  5. Click Ok


Done.!!!
Related Posts Plugin for WordPress, Blogger...