Friday, 14 December 2018

SharePoint 2013: Video file URL from Asset Library

When you are working with Asset library in SharePoint 2013. It is very important to note that how video files are stored and managed in that library.

By default, when you create Asset library it will come with Video content type. This content type will be used for managing the video files. When you upload a video file "sampleVideo.mp4" with the name "sameVideo". Then your video file will be accessible with below URL

http://<your site>/<your asset library>/sampleVideo/sampleVideo.mp4

This URL is little different from other SharePoint uploaded document URLs.  If you observe the above URL, name of the uploaded video file "sampleVideo" is additionally included. It means, when you upload a video file, it will create a hidden folder based on file name to store the following

  • Video file
  • Preview images
  • Additional content


After uploading the file, if you change the name "sampleVideo" to "testVideo" then your video file URL will be changed to below

http://<your site>/<your asset library>/testVideo/sampleVideo.mp4

So, when you are accessing or displaying video files dynamically via code with URL then you need to construct the URL in the above format.


Monday, 3 June 2013

SharePoint 2010: List templates missing

Recently I have deployed BDC model to a SharePoint site using visual studio. After that, I wanted to create a external list based on the deployed external content type.


But I have noticed there is no external list template under lists category on list creation page.Then I ended up activating the feature "Team Collaboration Lists Feature" under web features.

Team collaboration feature is for making standard lists, such as document libraries and issues, available. so if you all face any such issue just make sure Team collaboration feature is activated on your site.

Wednesday, 29 May 2013

SharePoint WebPart Life Cycle

It's important to know everything about webpart events and the sequence to avoid development mistakes.

Initial Load:

Events fired when a web part is initially loaded.

OnInit
OnLoad
EnsureChildControls
CreateChildControls
EnsureChildControls
CreateControlCollection
EnsureChildControls (many)
OnPreRender
EnsureChildControls (many)
SaveViewState
RenderControl
Render
RenderControl
RenderContents
RenderChildren
OnUnload
Dispose

Post-back:

OnInit
LoadViewState
EnsureChildControls
CreateChildControls
EnsureChildControls
CreateControlCollection
EnsureChildControls (many)
OnLoad
btnUpdate_Click
OnBubbleEvent
EnsureChildControls
OnPreRender
EnsureChildControls (many)
SaveViewState
RenderControl
Render
RenderControl
RenderContents
RenderChildren
OnUnload
Dispose



Like Asp.Net life cycle there is also Web Part life cycle. So it is better to understand the web part life cycle.


OnInit: This method handles initialization of the control.

OnLoad: This event handles the Load event. This is also used for initialize the control but is not intended for loading data or other processing functionality.

CreateChildControls: This is the most popular event in web part life cycle. This creates any child controls. So if you are adding any control to display then you have to write in this method.

EnsureChildControls: This method ensures that CreateChildControls has executed. EnsureChildControls method must be called to prevent null reference exceptions.

SaveViewState: View state of the web part saved.

OnPreRender: This method handles or initiates tasks such as data loading that must complete before the control can render.

Page.PreRenderComplete: The page fires the PreRenderComplete event after all controls have completed their OnPreRender methods.

Render: This method is used to render everything.

RenderContents: Renders the contents of the control only, inside of the outer tags and style properties.

OnUnload: Performs the final cleanup.

SharePoint: SPSecurity.RunWithElevatedPrivileges method

This is used to execute the specified method with Full Control rights even if the logged in user does not otherwise have Full Control.

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    // Your code here...
});


Note:

1.The RunWithElevatedPrivileges method can not be used within a sandbox solution

2.The item that is actioned with elevated privileges will be executed under the web applications App pool account in IIS, which means that the modified user of the document/list item will most likely display as SYSTEM ACCOUNT.

3.If you did not want to execute the code as the App Pool account for any reason, you could alternatively use a specific user account to execute the code under by implementing the SPUserToken class.

SharePoint: CAML Query not working based on WHERE clause

When we write the CAML query in SharePoint development and if we put WHERE clause in query it still returns all records.


For example look at the below query, it works fine in U2U builder but returns all records if we use the same in code.


SPQuery query = new SPQuery();
query.Query = "<Query><Where></Where></Query>"


Here is the Fix:

Remove the "<Query>" Tag and rewrite it

SPQuery query = new SPQuery();
query.Query = "<Where></Where>"

Wednesday, 22 May 2013

SharePoint 2010: Site Collection backup and restore using PowerShell

$FileLocation= "C:\testSite.cmp"

Backup:

Backup-SPSite -Identity $SiteCollectionUrl -Path $FileLocation -Force

Restore:

Restore-SPSite -Identity $SiteCollectionUrl -Path $FileLocation -Force -Confirm:$false

SharePoint 2010: Create site collection using PowerShell script

This article is about how to create a site collection in SharePoint using PowerShell script

$WebApplicationURL="http://testsite"
$SiteCollectionName="Test Site"
$SiteCollectionURL="http://testsite/sites/test"
$SiteCollectionTemplate="STS#0"
$SiteCollectionLanguage="1033"
$SiteCollectionOwner="domain\loginname"
$ContentDatabaseName="TestDB"


1. Create a site collection with a separate content database

#Create a new content database
New-SPContentDatabase -Name $ContentDatabaseName -WebApplication $WebApplicationURL

# Create site collection using new content database
New-SPSite -URL $SiteCollectionURL -OwnerAlias $SiteCollectionOwner -Language $SiteCollectionLanguage -Template $SiteCollectionTemplate -Name $SiteCollectionName -ContentDatabase $ContentDatabaseName  

2. Create a site collection with the default content database

New-SPSite -URL $SiteCollectionURL -OwnerAlias $SiteCollectionOwner -Language $SiteCollectionLanguage -Template $SiteCollectionTemplate -Name $SiteCollectionName

Thats it !!!



SharePoint 2010: Managed MetaData Service backup and restore using PowerShell script

Backup:

$mmsApplication = Get-SPServiceApplication | ? {$_.DiplayName –eq $MMSApplicationName}
$mmsProxy = Get-SPServiceApplicationProxy | ? {$_.DisplayName –eq $MMSProxyName}
  
Export-SPMetadataWebServicePartitionData -Identity $mmsApplication.Id –ServiceProxy $mmsProxy –Path $FileLocation


Restore:

$mmsApplication = Get-SPServiceApplication | where {($_.DisplayName) –eq $MMSApplicationName}
$mmsProxy = Get-SPServiceApplicationProxy | ? {$_.DisplayName –eq $MMSProxyName}  
 

Import-SPMetadataWebServicePartitionData -Identity $mmsApplication.Id –ServiceProxy $mmsProxy –Path $FileLocation –OverwriteExisting

Done!!!


Wednesday, 1 May 2013

Set Default value to Person or Group field in SharePoint 2010 using JavaScript and JQuery

This article is about how to set default value to person or group field when new list form opens using JavsScript and JQuery.

It includes the following

1. Get the members of a SharePoint group using SPServices JQuery library
2. Set the value to Person or Group field using JavaScript

<script type="text/javascript" language="javascript" src="/Style%20Library/JS/jquery-1.8.3.min.js"></script>
<script type="text/javascript" language="javascript" src="/Style%20Library/JS/jquery.SPServices-0.7.2.min.js"></script>
<script type="text/javascript">

    $(document).ready(function() {
      var strHTMLGroupUsers = "";
        $().SPServices({        
        operation: "GetUserCollectionFromGroup",
        groupName: "Approvers",
        async: false,
        completefunc: function(xData, Status) {
        $(xData.responseXML).find("User").each(function() {
          strHTMLGroupUsers += $(this).attr("Name")+";";
        });
      }
        });
        //get the people pickers input div
        var pp = getPickerInputElement("Approvers");
        //set it to the current user if we've found it
        if(pp != null)
        pp.innerHTML = strHTMLGroupUsers;
        $("img[title='Check Names']").parent().click();

    });

function getPickerInputElement(fieldsInternalName)
{
    var result  = "";
    var divs = document.getElementsByTagName("DIV");
    for(var i=0; i < divs.length ; i++)
     {
       if(divs[i].id=="WebPartWPQ3")
        {
          var tds = divs[i].getElementsByTagName("TD");
          for(var j=0; j < tds.length; j++)
           {
             var cellHTML = tds[j].innerHTML;
             
             if(cellHTML.indexOf('FieldInternalName="' + fieldsInternalName + '"') >= 0)
             {
               var innerDivs = tds[j].getElementsByTagName("DIV");
               for(var k=0; k < innerDivs.length; k++)
               {
                 if(innerDivs[k].id.indexOf("UserField_upLevelDiv") > 0)
                 {
                   result = innerDivs[k];
                   break;
                 }}}
             }
           }
        }
   return result;
}



</script>
 

Tuesday, 2 April 2013

Permission Issues when executing the PowerShell scripts

When we face any permission related issues while executing the PowerShell scripts, we need to check the following to fix it.

1. Check Window PowerShell execution policy
   Get-Execution Policy

2. If the return value is "Restricted" and then set the value as "RemoteSigned"
   Set-Execution Policy "RemoteSigned"

3. In addition to the above, also need to ensure that UAC (User Access Control) is disabled.

That's it.

Sunday, 24 February 2013

SharePoint: Edit the WSP file contents and rebuild it.

This topic is about how to edit the contents/files of WSP file and rebuild it.

In a recent time, I come to a situation where I need to extract the WSP file to edit the files like ONET.xml, feature.xml, etc. Exacting contents of WSP and modifying them is fine but rebuilding the WSP is not straight forward and its not possible by just renaming it.

After spending some time, I ended up with the following approach to rebuild the WSP successfully.

Step 1 : Rename WSP file to CAB and extract all the files

1. Rename the WSP file to CAB
2. Extract the CAB file using 7 Zip or any other tool

Step 2: Modify the necessary files.

Step 3: Use DDFGenerator from CodePlex

Now, we need to generate a DDF file using a CodePlex component DDFGenerator based on our WSP contents. It is an executable file.

1. Download the DDFGenerator and place the file in any of the physical drive folder
2. Open the DDFGenerator folder path directory in Command prompt
3. Enter the following command with the path to our WSP file contents folder

C:\[DDFGeneratorFileFolder]>  DDFGenerator "C:/path/WSPSolutionFolder"
4. The above command will create a DDF file with the name "solution.ddf"
5. DDF Generator doesn't put an entry in DDF for WSP file name. So it is required to edit the ddf file to put the following entry similar to other entries in the DDF file (mostly as a second entry) create WSP file

.Set CabinetNameTemplate=<SolutionName>.WSP

6. Check if file paths in DDF are having spaces in between. If yes, enclose file path using double quotes. This is required to avoid errors while executing the next step.

Ex:  .Set DestinationDir = "1TeamSiteListInstances\Files\Lists\Team Discussion\"
        "1TeamSiteListInstances\Files\Lists\Team Discussion\Schema.xml"

Step 4: Run MakeCab.exe to create CAB and WSP files

Now we need to run MakeCab command as below to generate WSP file.
C:\[DDFFileFolder]> "MakeCab.exe /F <solution.ddf> "

After executing the above command, the WSP file will be created. (A folder with a random number as name will be created and WSP file will be placed in that folder).

Thats it !!!
 

Sunday, 22 April 2012

SharePoint 2010: Content Organizer Feature


For those of you who may not be aware, SharePoint 2010 has an interesting new feature called the Content Organizer. The Content Organizer feature is quite a powerful document routing solution that makes it easier to store documents consistently, according to administrator defined rules that can copy or move a document from one place in SharePoint to another place. I will get to the rules in a minute, but the content organizer feature is important for several reasons;
  • It makes the saving of documents easier because users do not necessarily have to worry about knowing the destination when uploading new content.
  • It is a highly flexible method for routing documents between sites and site collections around the SharePoint farm.
  • It underpins a solid compliance and records management file plan capability.
So before anything else can be done, we need to turn it on. The Content Organizer feature has to be activated on each site for the functionality to be enabled. In other words, it is a site scoped feature. Below is an illustration of the feature to activate.


Once the Content Organizer feature is activated, SharePoint 2010 makes several changes to the site configuration.
  • It creates a new document library called the Drop-off Library.
  • It creates a new custom list called Content Organizer Rules.
  • It adds two new Site Administration links in the Site Settings page to manage the Content Organizer for the site.

The description for the feature says “Create metadata based rules…” and it these Content Organizer rules that allow you to automatically route documents from the newly created Drop-off Library to some other location. It is important to know that the Drop-off Library is fixed – it is the first point of call for files that need to be moved or copied somewhere. Consider the drop-off library like a bellboy of a hotel. You give him your luggage and he will ensure it gets to its correct location (and unlike a bellboy you don’t need to tipJ).
So if the drop-off library is the starting point, where can documents are routed to? The location can be;
  • A document library and/or a folder within a document library on the site.
  • The Drop-off library of another site, which allows inter and intra site collection routing.
The Content Organizer rules are managed from Site Administration which is accessed via Site Settings. New rules are added in the same manner as adding new items to any SharePoint list. In the following example, we will create a rule where content types of invoice will be routed to a document library called Finance.


 
The conditions section of the rule allows for multiple conditions to be defined determining matching content and then, where that content should be routed to. The properties available are any columns assigned to the content type being routed. In the example below, we have added two conditions that have to be satisfied before the rule will fire.



Let’s take a closer look at this beast known as the Drop-off library. This is a special document library is added to the site upon feature activation, imaginatively called the Drop off Library. As stated earlier, this library is really a temporary staging area for items that do not have all required metadata to satisfy any routing rules.
The sequence of events for the Content Organizer is;
  1. Documents with the correct content type, metadata, and matching rules are automatically routed to the final library and folder.
  2. Documents that lack the amount of metadata required to match a rule or that are missing required metadata are retained in the "Drop-Off Library" so that the user can enter metadata to satisfy a rule.
  3. After a user has edited a staging document with the appropriate metadata required to match a rule, the document is automatically routed to the target library and folder.
As an example, if we assume that a Content Organizer rule will route any document with “Finance” in its name to document library called Finance, the behavior will be as follows:
  • If the file uploaded has the word “finance” in its name, SharePoint indicates that the document has been successfully routed
  • If the file uploaded does not have the word “finance” in its name, SharePoint will indicate to the user that the content organizer has placed it into the Drop-off library.
Now, before you rush off and start to mess with the content organizer, I’d better tell you about a couple of caveats
  1. The Content Organizer will only work on content types that are, or derive from, the Document content type. So it does not work for automatically organizing large lists.
  2. When uploading documents via Windows explorer view, Content Organizer rules are ignored and the document will not be redirected to the Drop-off library. (through the browser if a document is uploaded to a destination library, SharePoint will move it to the Drop-off library for classification)
  3. There is a limit of six conditions per rule. After six conditions are added, the "Add new condition" link disappears.
  4. If you wish to route the document to another site, the Content Organizer feature has to be installed on that site for the Drop-off library to be created as that is the destination. Additionally, you need to add the configuration information in Central Administration by adding the destination to the list of send to connections for the web application (that is beyond the scope of this article, but easy enough to do).
  5. There are also some potential risks around the fact that you can route files to any destination even if you do not have permission and potentially overwrite content. The content organizer will move content to the new location whether or not the contributing user has access to the destination location.

SharePoint 2013: Video file URL from Asset Library

When you are working with Asset library in SharePoint 2013. It is very important to note that how video files are stored and managed in tha...