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 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...