Friday, May 31, 2013

SharePoint "Download A Copy" from a SP Document Library

Generate a link using below format:
http://spsite/subsite/_layouts/download.aspx?SourceUrl=http://spsite/subsite/shared documents/file.docx

And use this URL in Anchor tag / window.open etc. as per the requirement.

Hope that helps.

Friday, May 17, 2013

Get 14 Hive Path Programmatically In C# ( SharePoint 2010)

Use simple one liner code to get 14 hive path using C#:
string setupPath = SPUtility.GetGenericSetupPath(string.Empty);

Method is included in Utilities namespace:
using Microsoft.SharePoint.Utilities;

Above method will return C:\Program Files\Common files\Microsoft Shared\Web Server Extensions\14

Contact Me or post a comment for any technical help related with SharePoint 2010.

Tuesday, May 7, 2013

Using JavaScript In OnLoad Event Of Body SharePoint 2010

When developing web parts or other SharePoint controls many times we might require to call some functions on body onload event. As web part does not contain body tag we cannot use onload attribute of body tag.

To overcome this drawback, a developer can use an array i.e. _spBodyOnLoadFunctionNames
The only thing we need to do is to pass the function's name using .push method.

Example:
<script language="javascript">
_spBodyOnLoadFunctionNames.push("TestFunction");

function TestFunction() 

   alert("hello"); 

</script> 

We can use above script in master page, aspx page, content editor web part, visual web part as per the need.

Contact Me or post a comment for any technical help related with SharePoint 2010.

Thursday, May 2, 2013

Access The Outbound SMTP Server Address From Code

Use following one liner code to get the Outbound SMTP Server Address:

SPContext.Current.Web.Site.WebApplication.OutboundMailServiceInstance.Server.Address


Contact Me or Post comments for any technical help related with SharePoint 2010.