Friday, August 31, 2012

Custom Web Part to Add document to SharePoint document library

I am categorizing this post into two parts. First part is just to make foundation for this post.

PART I:

To display files and folders of a document library in a tree view style you will need to create a custom web part and for that, you can always refer this link:
http://www.codeproject.com/Articles/37530/Document-Library-Tree-View-Web-Part-for-SharePoint














Now, let's come to the second part which is also the focus of this post.

PART II:

Now suppose, you need to add a document from above web part while refreshing the tree view at the same time.
















Given below is the code to achieve this:



Code Description:
a.) Get document library permission level for logged in user so that 'Add Document' link can be hidden for less privileged users.
b.) Put 'Add document' link on web part with SharePoint look and feel. On clicking, it calls a java script function which is registered using 'RegMyScript'.
c.) It adds document to document library in the SharePoint way and also refreshes library tree view to show the newly uploaded document.

Code Download Link.

Tuesday, August 28, 2012

Using Multiple Selection List Box control in InfoPath 2010

Multiple Selection List Box control acts like a list box which can be populated with values stored in a SharePoint list while rendering items with a check box in front of them at the same time.

Here, we will look into two capabilities of this control which are not very straight forward:

  • Retrieving all selected options with a delimiter
  • Show/Hide input details mapped with one of the item in control


Retrieving all selected options with a delimiter

Let's say, you have the requirement of getting all selected items from Multiple Selection List Box control and need to promote these to SharePoint form library.

(To promote this control value, you select 'merge' from drop down at the time of property promotion.)

Here comes the problem !

You may find promoted values unexpected as selected values are merged without any separator/delimiter. This control doesn't provide any option for putting a delimiter between merged values.

To achieve this, you need to work with expressions in InfoPath.

At the time of Submit,
- Create a rule to store provided expression (below) in any hidden control.
- Promote hidden control to SharePoint form library instead of multiple selection list control.

Syntax:
substring(eval(eval(lbControl[. != ""], 'concat(", ", .)'), ".."), 3)     // Store this into hidden control

Description:
It is using eval function of InfoPath which iterates through every item of list box control and put a prefix ", " with item if selected. lbControl is our list box control.


Show/Hide Input Details mapped with one of the item in control

Let's say, we have a requirement of making a control (text box, drop down list etc.) visible or invisible based on selection of a particular item in multiple list box control.

Put your target control in a section and create a formatting rule on section saying like this:

a.)









b.) And, if above condition is true, then hide the section.

Description:
lbRequestType -> This is your multiple selection list box control
"IT Department" -> It is an item populated in multiple selection list box control.

Launching applications from Internet Explorer browser

Solution provided here assume that application is placed on a known location on any client machine (for e.g. Notepad.exe).

I have used ActiveX with shell scripting for launching Win32 (Non Win32 can be launched too) applications.

JavaScript Code: