Posts

Bryce Canyon National Park

http://www.campingroadtrip.com/tips-and-articles/bryce-canyon-national-park

Adding Validation to a Custom NewForm.aspx in SharePoint & Redirect

SharePoint has a built in function called "PreSaveAction" that can be invoked to process anything before the form should submit. So now we will create a submit button which calls “PresaveActon” function. Once users Submits the form, PreSaveAction is executed. If PreSaveAction is returns true it will commit and redirect. If the PreSaveAction returns false, then the commit will not happen nor the redirect. Input Button Code: Replace this code <SharePoint:SaveButton runat="server" ControlMode="New" id="savebutton1"/> with <input type="button" value="Submit" name="btnSave" onclick="javascript: if(PreSaveAction()) {ddwrt:GenFireServerEvent('__commit;__redirect={http://<Site>/ SitePages/ThankYou.aspx}')}" /> Add Script in NewCustom Form. Now edit New custom newform.aspx and add content editor webpart and with below script <script type="text/javascript...

show append changes to existing multiline textbox in Custom Edit/Display form

To show append changes to existing multiline textbox, use below code: <SharePoint:AppendOnlyHistory runat="server" FieldName="multiple field" ControlMode="Display" ItemId="{@ID}"/> How to Add: 1. in custom display form Try to create a new custom display form in Designer, select the multiple field, then go to code, tries to use the above code to replace <xsl:select value-of="@multiple field" /> 2. In custom edit form Try to create a new custom edit form in Designer, select the multiple field, then go to code, try to use the above code to replace      <SharePoint:FieldDescription runat="server" id="ffndescription{$Pos}" FieldName="mul" ControlMode="Edit"/>

Export and Import SharePoint Designer List Workflow

Exporting and importing of the List Workflow to and from another list or site is actually a non-supported feature. However, there is a "workaround" to achieve this.  In SharePoint Designer 2010, click on your completed List Workflow. Click on "Save" and "Publish" for the completed List Workflow. Next, click on "Export to Visio". Save the file as CompletedWorkflow.vwi or any preferred name. Then create a new "similar" list on the current site or on a new site collection. There is no way to import the exported visio into this new list. In SharePoint Designer 2010, click on this new list and then click on "List Workflow" to create a new workflow for this new list. Please make sure that you do not add any workflow steps! Click on "Save" and "Publish" for this empty List Workflow. Then, click on "Export to Visio" and save this as EmptyWorkflow.vwi or any preferred name. Rename both the...

InfoPath form Contact selector

 The Contact Selector consists of 3 data nodes: DisplayName AccountId AccountType Each is just a text field.  When you publish your form, you have the option of promoting one or all of the fields. DisplayName only contains the PreferredName attribute of the User Profile Database, which is typically in the form of LastName, FirstName, but it depends on your AD setup. AccountId is the most valuable field, because it contains the user's domain name in the form of domain\username (i.e. microsoft\userId).  If you promote this field to SharePoint, then this value is immediately usable for sending workflow emails in SharePoint Designer.  I do this all the time.  Also, that value can have the domain portion stripped out and be used to query the GetUserProfileByName web method to retrieve the selected user's profile info, including Email Address, Manager, Department, and many other attributes stored in the profile database. Since these are text fields, th...

ECMA Script : To get current logged in user information from User Profile Service Application

ECMA Script to get current logged in user information from User Profile Service Application using "SP.UserProfiles" script files. <!--script src="/_layouts/15/Scripts/MicrosoftAjax.js" type="text/javascript"></script--> <!--script src="/_layouts/15/init.js" type="text/javascript"></script--> <script src="/_layouts/15/sp.runtime.js" type="text/javascript"></script> <script src="/_layouts/15/sp.js" type="text/javascript"></script> <script src="/_layouts/15/SP.UserProfiles.js" type="text/javascript"></script> <script type="text/javascript">     //$(document).ready(function(){         SP.SOD.executeOrDelayUntilScriptLoaded(getUserProperties, 'SP.UserProfiles.js');     //});     var userProfileProperties;     function getUserProperties() {         var clientContext = new SP.ClientConte...

ECMA Script : To Add current logged in user to SharePoint group 2013/ 2010

<html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type="text/ecmascript"> ExecuteOrDelayUntilScriptLoaded(init,'sp.js'); var currentUser; var currentUserName; var currentUserEmail; var currentUserLogin; var siteUrl = '/'; function init(){     var clientContext = new SP.ClientContext.get_current();     var oWeb= clientContext.get_web();           currentUser = oWeb.get_currentUser();     clientContext.load(currentUser);     clientContext.executeQueryAsync(Function.createDelegate(this,this.onQueryUNSucceeded), Function.createDelegate(this,this.onQueryUNFailed)); } function onQueryUNSucceeded() {   currentUserName = currentUser.get_title(); currentUserLogin= currentUser.get_loginName(); currentUserEmail= currentUser.get_email(); document.getElementById('txtUserName').innerHTML =  currentUserName; document.getElementById('txtloginName').innerHTML =  curr...

Get relative path and name of the active Script in PowerShell

# Get complete file path (eg: D:\RootFolder\ActiveScript.ps1) $0 = $MyInvocation.MyCommand.Definition # Get current Directory file path (eg: D:\FolderA) $dp0 = [System.IO.Path]::GetDirectoryName($0) #To Get the root folder $RootPath = $dp0 | split-path # Get current Drive (eg: D:\) $bits = Get-Item $dp0 | Split-Path -Parent

Check Running Timerjob Status using Powershell

Check the status of timer jobs that have been run by using Windows PowerShell. $Job = Get-SPTimerjob "TimerJob Name" [Array] $JobHistoryList=$Job.HistoryEntries Start-SPTimerJob $Job Write-Host "Running Timer Job" -NoNewline $count = $JobHistoryList.count $countNext = $count+1 while ( $countNext -ne $count) { [Array] $JobHistoryList=$Job.HistoryEntries $count = $JobHistoryList.count Write-Host "." -NoNewline sleep 2 } if ($taxonomyjob[0].status –ne "Succeeded") { Write-Host -f yellow $JobHistoryList[0].status Write-Host -f yellow $JobHistoryList[0].ErrorMessage } else { Write-Host $JobHistoryList[0].status }

"The Selected file was not found” Error When Adding an Attachment to an InfoPath Form

Adding the following bit of JavaScript to the WrkTaskIP.aspx page, which is responsible for hosting the InfoPath task form: <script type="text/javascript"> aspnetForm.encoding = "multipart/form-data"; </script> Another approach documented here suggests modifying the application.master master page file to add the necessary enctype form tag: <form runat="server" onsubmit="return _spFormOnSubmitWrapper();" enctype="multipart/form-data"> ... </form

Embedding InfoPath Form in SharePoint Page

Add the following line in the <SafeControls> tag of the web.config file of your web application in all servers: <SafeControl Assembly="Microsoft.Office.InfoPath.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.Office.InfoPath.Server.Controls" TypeName="*" Safe="True" /> Open Portal. Under Site Actions, click Site Settings. In the Site Settings page click Web Part Gallery link. In the Web Part Gallery page , click New. We will be redirected to the Web Part Gallery : New Web Parts facility. In the Web Part Gallery : New Web Parts part, check Microsoft.Office.InfoPath.Server.Controls.XmlFormView . Then, click Populate Gallery. We will be redirected again to the Web Part Gallery page where we can verify the inclusion of XmlFormView.webpart. Now open the page where you want to add the infopath form In the Site Actions, click Edit Page. the page will be set to Edit Mode. Cli...

WebPart Life Cycle

1. OnInit: event used to create controls of web part 2. OnLoad: 3. CreateChildControls: event used to set properties and default values to controls collection If the page is being rendered for the first time the method generally occurs after the OnLoad event. If it is Postback, It is called before OnLoad event. EnsureChildControls: It checks to see if the CreateChildControls method has yet been called, and if it has not, calls it. 4. LoadViewState: The view state of the web part is populated over here. 5. OnPreRender: event used to set up business logic related work and in this routine controls value kept by viewstate 6. Render: event creates the HTML that appears in the body of the Web Part. 7. OnUnload: 8. Dispose:

Creating Views in SharePoint Using the object model

Using the object model we can create a SharePoint views programmatically. The query for the view uses an SPQuery which uses CAML. //Define an array to hold the columns required in the view String[] colArray = new String[] { "FName", "LName", "Email” }; //Add the array to a string collection StringCollection colCollection = new StringCollection(); colCollection.AddRange(colArray); //Define the query for the view String viewQry = “Your CAML Query Here’; HTML clipboard //Define the new view & Add to the List (100 is the item limit, true is allow paging and false is to set as the default view) SPView newView = YourList.Views.Add(“View Title”, colCollection, viewQry, 100, true, false);

How to modify the width and height of a Sharepoint Page Viewer web part dynamically

You can use following JavaScript code to dynamically adjust width and height of the page viewer web part. Just put it in each asp.net page that you want to display in a page viewer, and the problem will be solved: JavaScript code: function resizeMe(that) { window.resizeTo(document.body.scrollWidth, document.body.scrollHeight); } window.attachEvent("onload", function() { window.setTimeout("resizeMe()", 100); }); Alternatively, window.resizeTo(window.screen.availWidth, window.screen.availHeight); can also be used.

Adding Contact Selector Control to InfoPath form

The Contact Selector control is an ActiveX control but it is a special cased control, in that it can also be used in InfoPath browser forms. To use this control there are specific steps that need to be taken – let’s take a look at those now. Step 1 : Steps to add Contact Selector control to your Controls Task Pane 1) From the Controls Task Pane click "Add or Remove Custom Controls" link 2) Click the Add button 3) Add Custom Control Wizard select "ActiveX control" and click Next 4) This will display a list of controls , select "Contact Selector" ,click Next 5) Select “Don’t include a .cab file” and click Next 6) For Binding Property select Value and click Next 7) From the Field or group type box choose Field or group (any data type) and click Finish 8) Click Close and then click OK Step 2: Create the data structure for the Contact Selector Control The Contact Selector control needs to have a specific data structure to work properly – this is documented on...

Diff between Site Pages Vs Application Pages

Site Pages: Pages that support user customization are known as site pages and stored in the content database. Ex. Site pages default.aspx, NewForm.aspx, and EditForm.aspx. Site pages customization provides flexibility but can also impact performance and scalability Each page would also have to be individually parsed and loaded into memory.. Site pages do not support in-line code under the default security policy enforced by WSS. Application pages: Application pages do not support customization, which gives them two distinct advantages over site pages. First, each application page is always compiled into a single DLL so that it performs and scales better than a site page. Second, application pages are allowed to have in-line code. Ex. Settings.aspx, uagedetails.aspx. Application pages are deployed as physical files on file system of front end web server on the server's file system. An application page, such as settings.aspx, can be accessed by adding its relative path within the _...

How to Add onLoad JavaScript event in SharePoint?

SharePoint provides a JavaScript array “_spBodyOnLoadFunctionNames”, any function to be executed onLoad needs to be added to this array e.g. _spBodyOnLoadFunctionNames.push("ExecuteMyFunctionOnLoad"); Now, why does your JavaScript function doesn’t execute if you just register it with ClientScript.RegisterStartupScript? Actually, content pages can’t execute JavaScript function on body load, reason; content pages can’t directly add a function to the body’s OnLoad event if master page contains the <body> element (which is mostly true). This array is basically a part of init.js located in “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033\”. If you open the javascript file, you will notice the page onLoad event is handled by function _spBodyOnLoadWrapper, which further calls ProcessDefaultOnLoad, and this function executes all the function names added in array "_spBodyOnLoadFunctionNames". function addLoadEvent ( func ) ...

CREATING AND DEPLOYING FEATURE IN MOSS

Image
Windows SharePoint Services 3.0 introduces an inherently portable and modular functionality known as feature, which provides a mechanism for defining site elements. A feature is a package of Windows SharePoint Services elements that can be activated for a specific scope and that helps users accomplish a particular goal or task. Features are added to a target site or site collection through a process known as feature activation. The element types that can be defined by a feature include menu commands, link commands, page templates, page instances, list definitions, list instances, event handlers, and workflows. So let’s start writing a feature. The functionality of the feature which we are going to develop is that it adds a menu item “Hello World” in the “Site Actions” menu. Clicking on the menu item “Hello World” will transfer to Google. Our goal is shown in the figure below: The first step is to understand the feature file structure. If you go to “C:\Program Files\Common Files\Microso...

MOSS 2007: Site Usage Report Error

Scenario: When click on “Site Usage Reports” under “Site Administration” in “Site Settings” page, the following message displayed: Both Windows SharePoint Services Usage logging and Office SharePoint Usage Processing must be enabled to view usage reports. Please contact your administrator to ensure that these services are enabled. Resolution: You have to enable two options. Open “Central Administration” -> “Operation” and click on “Usage analysis processing” under “Logging and Reporting” and check “Enable Logging”. Then, move to “Shared Service Provider”, Click on “Usage reporting” under “Office SharePoint Usage Reporting” and check both options.

Deleting Webparts When error occured

Sometimes it is difficult to delete or edit a web part. When clicked on “Modify Shared web part” link, error page appeared “An unexpected error has occurred. ” One way to delete the web part is to go to web part maintenance page and delete it. This can be done by adding “? contents=1” to default.aspx page.