Monday, December 5, 2011

Refresh Pivot Table or Chart with Excel Service when Sharepoint List update



EXCEL SERVICE CONFIGURATIONS


Excel Service will help to use Excel Workbook (Client) functionality in a browser. However, Excel Service can’t leverage all Excel Workbook functionality on Browser. Below documents will point to all configurations settings to take advantage of Excel Service and how to get dynamic updates in Excel Web Access Web Part from Sharepoint List as soon as Sharepoint List updates. I am dealing with SharePoint 2007 (MOSS) and Excel Workbook 2007.

Note
1. Keyword Pivot Chart/Table is abbreviated as Chart. 
2. Excel Workbook is abbreviated as Workbook. Workbook indicates workbook in Trusted Location which consists of Pivot Chart/Table to be loaded on Web part.
3. DataBase is abbreviated as DB.

Below are couple of items where we need to make setting:
v SSP (Sharepoint Service Provider) on Central Admin.
1.       Trusted File Location:
Create a location on your site by clicking on Add Trusted File Location. Trusted location where all Excel Workbook will be uploaded. Excel Service will only load Workbook which is in Trusted Location. As of now, I have created trusted location in my Tool site’s Shared Document.

Location Type: Set Location Type as Window Sharepoint Service, if you are uploading Workbook in Sharepoint. If your workbook is on network then you can choose UNC option. If your workbook is on Web then you can choose HTTP option.
  
Trust Children:
Check Trust Children box, if your workbook is uploaded to any sub-folder under URL given in Trusted Location, Excel Service will considers sub-folder as a Trusted Location to load workbook. In our case, we are uploading Workbook under Excel Service folder under Shared Document.

Session Management:
Keep “-1” value in Session Timeout, Short Session Timeout and Maximum Request Duration for never ending session (Below screen)

Workbook Properties:
Keep default values in Maximum Workbook Size and Maximum Chart Size.

Calculation Behavior:
Volatile Function Cache Lifetime: Set it to “-1”
Workbook Calculation Mode: Set it to Automatic

External Data:

Allow External Data:
Set it to Trusted data connection libraries and embedded as we will configured connection in Data Connection Libraries in Sharepoint and data connection will also seats inside Workbook. Choose None if your Workbook has no connection to connect to Data Source.


Warn On Refresh: Check it if you want warning on page (where Web part is loaded) before Excel Service update your Chart. As of now, un-check it.

Stopping open enabled: Check it.

Automatic refresh (periodic / on-open): Set it to “-1” if you don’t want automatic update. You need user to get the updates whenever they need. Keep Manual Refresh to “0”.

Maximum Concurrent Queries Per Session: Keep default value to “5”

User-defined functions allowed: Uncheck it, as we are not dealing with .Net assemblies.

1.       Trusted Data Connection:
We need to create Trusted Data Connection in SSP which actually act as an interface to get the updates from Database. Excel Service will get the updates via this Trusted Data Connection only. Trusted Data Connection Libraries is merely a folder where data connection file is uploaded. This data connection file consist of every stuffs require by SQL Server Database like Connection String, Command Text, SQL View name etc.

Let’s create Trusted Data Connection Library on Sharepoint:
a.       Navigate to your site.
b.      Click on Document link on left panel.
c.       Click on Create.
d.      Click on Data Connection Library under Libraries section. Data Connection Library is specific meant for storing Data Connection files only.
e.      Specify useful name. In my case, I have created Data Connection Library under Tool site and gave name as DCL.
f.        Click Ok

Let’s configured Trusted Data Connection on SSP:
g.       Click on SSP
h.      Click on Trusted Data Connection Libraries.
i.         Click on Add Trusted Data Connection Libraries to add trusted data connection.
j.        Specify DCL path. Note:  You can trim “Forms/AllItems.aspx” in the path. In my case, path will be “http://mysite/sites/Tool/DCL”

2.       Trusted Data Provider:
Microsoft has already specified many standard Providers. We can either use it or create new one based on our requirement. In my case, I have used “SQLOLEDB.1” in my connection string. We will see it shortly.

v SQL View

1.       Creating SQL View to query to Sharepoint List (to prepare Chart in Workbook):
§  Mapping field name in DB table with Sharepoint List column.
SQL Server is the backend Database for Sharepoint. So, every data in Sharepoint resides in SQL Server DB. However, SQL Server doesn’t maintain separate table for each Sharepoint List/Library/Site. But, it maintain single table called as “AllUserData” as a repository for Sharepoint data. So, we will target “AllUserData” table to generate SQL View.

Before jumping to AllUserData, We need to get the columns name in SQL Table mapped with Sharepoint List column. Yes, you read correctly. Each column in a list is mapped to inbuilt columns in Sharepoint. E.g. First Name column in a XXX list is mapped with "nvarchar1" column in DB and Last Name column in "nvarchar2" column & Amount in "float1" etc.


SQL DB maintain schema for all list. This Schema will maintain all information on mapping. We can get Schema from tp_Fields column in AllLists table. However, we are interested in Schema only for our required List. So, use tp_Titles column in AllLists table. Use below query

Select tp_Titles, tp_Fields From AllLists
where tp_Titles = 'XXX'
Note: If you don't know your list name then you can use Wildcards e.g. tp_Titles like '%XXX%'. 

Search your list name from tp_Titles and copy/paste data from Schema column to text file. Now, search for your Sharepoint List column name in text file and get the mapped column name in Database.
e.g.
<Field Type="DateTime" DisplayName="Date Identified" Required="TRUE" format="DateOnly" ID="{ec34b242-f0fd-448e-8507-08e387230da4}" SourceID="{2e4d8f89-a5bb-480d-9047-0d7a02749e07}" StaticName="Date_x0020_Identified" Name="Date_x0020_Identified" ColName="datetime3" RowOrdinal="0" CalType="0" Version="1"><Default>[today]</Default></Field>

Every column starts/ends in Field tag. So, search your column name with CTRL-F and get the mapped name. So, in above case, I am interested in “Date Identified” columns name. So, it is mapped in ColName field. So, column name is mapped in datetime3 in Database. Database store the value in same column type based on column type in Sharepoint List. In our case “Date Identified” is a datetime type, so it is mapped under datetime data type in Database. While, “Single Line of Text” column type will store data in nvarcharN column in Database. N could be integer value upto 64.
In our case, we will create below view.


§  Creating SQL View:
select nvarchar40 as "Column1", nvarchar30 as "Column2"
 from AllUserData
where tp_DirName='sites/XXX' and tp_DeleteTransactionId = 0x & Is_current=1


Notetp_DeleteTransactionId indicate removing deleted records from your result set. Because, sharepoint also maintain Recycle bin's data in "AlluserData". While, Is_Current indicates rows with current version.

Give senseful name to your view and save it.



v Data Connection in Excel Workbook
We need to create connection from workbook to Database to fetch Sharepoint List column value. So, we will target SQL View (created above) for the connection.

Follow below steps to create and configure Data Connection:
1.       Click on Menu Data -> From Other Sources -> From SQL Server.
2.       Provide your Database Server name. In my case, its “162.70.211.11”.
3.       Click on option: Use the following Username and Password.
4.       Click Next button.
5.       Select your Database name in “Select the database that contain the data you want” dropdown.
6.       Select your SQL View (which we created above)
7.       Click Next.
8.       Give your  Filename.
9.       Click on “Save password in file” checkbox.
10.   Specify your friendly name. In my case, both Filename and Friendly name were same.
11.   Check “Always attempt to use this file to refresh the data”.
12.   Important: Click on “Authentication Settings…” button. Choose None as we are using SQL Authentication to get the data. Please note, Clicking on None is important, as we are connection to Database via SQL Authentication and not by Windows or SSO authentication. So, select None.
13.   Click Finish to complete data connection configuration.
14.   You will receive below Import Data dialog box.



15.       Click on Properties button to Export this settings to Sharepoint Data Connection Library. This data connection library we can also reuse.
16.       Check Enable Background Refresh check box in Usage tab.
                          17. Enter “1” minute in Refresh Every…Minutes textbox.
                          18. Your settings should look like below screen:





19. Click on Definition tab.
20. Check “Always use connection file” checkbox.
21. You should get complete connection string in Connection String text box which include Username, Password, Provider etc.
22. Check on Save Password check box.


23. Command Type should be Table.
24. You should get SQL View name (which we created in Database) in Command Text.
25. Now, click on Export Connection File to export this setting in Data Connection Library.
26. Your Connection Properties dialog box should look like below:



27. That’s it. You are done.
28. Now, you can create your Chart based on your requirement.
29. Click on Existing Connections in Data menu in your Excel Workbook.
30. Click on Connection name which we created above.
31. Click on PivotChart and Pivot Table Report option in Import Data dialog box.
32. Click Ok.


33. After preparing Pivot Chart and Table, you need to publish Workbook onto Sharepoint Trusted Location.
34. Click on Workbook Ribbon (on top-left corner) -> Publish.
35. In Save As dialog box, click on Excel Service Options button.


36. Note: Open in Excel Service check box should be checked, so after publish your Pivot Table and Chart is display in a browser. This is useful feature by Excel, as we can get errors immediately (if any) in browser, rather than loading the Workbook in Web Part and then getting the result.


37. In Show tab, click on Items in the Workbook.
38. Check Pivot Chart and Table you want to publish in Web part.
39. Click Ok
40. Specify URL which point to Trusted Location on your site. In my case, path was: “http://..../sites/Tool/SharedDocuments/Excel Service/”


41. Specify Workbook name and Click Save button to publish the workbook.


Data Connection File in Sharepoint:
When we exported Data connection (in Step-15) from Workbook, it got copied in Sharepoint Data Connection Library (which we created in “Trusted Data Connection” in SSP section).
1.       Move yourself to Data Connection Library page.
2.       Click on Data Connection file drop down.
3.       Click on Approve/reject item – See below screen. 
     Note: This step is very important, as change in web part won’t appears without approving this connection file.


4. Click on Approved/reject option.
5. Click Ok.

 Excel Web Access Web Part
Add an Excel Web Access web part in your page to load Pivot Table and Chart. You can add this web part following below steps:
1.       Navigate on the page where you want to load Excel Web Access Web Part.
2.       Click on Site Actions -> Edit this page.
3.       Click on Add Web Part in Add Web Parts dialog box.
4.       Move to All Web Parts section.
5.       Check Excel Web Access check box. See below screen.


6. Click on “Click here to open the tool pane” to open dialog box for web part configuration. Here, we will specify workbook location with few settings.



7. Specify workbook which you published in Workbook text box.

8. Specify Chart or Pivot Table name in Named item text box. 
Note: Please specify precise name of Chart/Pivot Table from the work book or else Web Part may not display Chart.
9. Click Ok.

10. Now, you should see your Pivot Chart/Table.
11. To get the refresh immediately, user need to click on Menu Update -> Refresh All Connections.

Monday, March 7, 2011

Connecting Infopath form to Specific view in a List

Target User: Infopath Developer & Sharepoint Developer.

There are situation where we need to connect to specific view in a List. In my case, i had to populate my Infopath drop down with column values from a Sharepoint List.However, by default List can show only 100 records/items per page. So, my drop down will populate with only 100 items out of 600. So there are 2 ways to populate all 600 items in drop down:

  1. Either change your default view to show all 600 items per page.
  2. Create another view and make it to display 600 items per page.
Approach-1:
Displaying 100 items per page to 600 items per page by following below steps:
  • Click on your default view menu (top-right corner).
  • Modify View.
  • Move to 'Item Limit' section.
  • Change 100 to 600
  • Ok
Problem with Approach-1:
  1. Your requirement will not allow to display all 600 items per page.
  2. This will hit the performance, as for each page refresh; 600 items has to get loaded.
Approach-2:
With this approach, you can create another view which will display 600 items. This view you can use it for your internal stuffs only. While, user will see default view listing 100 items.

How to do this?
  1. Create New data connection which will retrieve data.
  2. Check option to receive data from XML document.
  3. (Important Step) Enter below URL to connect to specific view 
http://server-name/sites/site-collection/sitename/_vti_bin/owssvr.dll?Cmd=Display&List="list guid"&XMLDATA=TRUE&View="view guid"

  • URL in black should be your default site URL.
  • _vti_bin/owssvr.dll?Cmd= Display&: It should be constant as given. 
  • List="list guid": Indicate Sharepoint List to connect. e.g. List=%7B058B2418%2D6EAE%2D4870%2D919A%2D5FC55C05C49D%7D
  • &XMLDATA=TRUE: Indicate connecting and retrieving XML data.
  • View="view guid": Indicate connecting to specific view. User can get the GUID's for a List and View by following below steps:
    • Click on Settings menu.
    • Form Library Settings
    • Navigate to Views section.
    • Click on the view where you want to connect.
    • Check out URL bar where you will find View Guid.

Hope this article could save your precious time.

- Chintan, Bangalore,
- India



Friday, January 14, 2011

Content Type


Content Type is a new feature in MOSS and WSS 3.0. Content types provide a means to manage the metadata and behavior of SharePoint list items, making it possible to store different types of content within the same library or list. A single web site could contain many types of content, such as informational pages, news items, polls, blog posts, real estate listings, etc. Each content can differ based on their categories and metadata (columns). e.g. Student Content Type has metadata such as Student Name, Address, Standard. Employee Content Type has metadata: Employee name, Address, Salary, Department.

Consider Content  Type as a Class in OOPs programming and Column as a field or properties in a Class.

Similar to Class, Content  Type is reusable component in moss. Once we define content type, we can use it or refer it in multiple location.



Friday, January 7, 2011

Referring Dll in Sharepoint 2007

Referring Dll in Sharepoint 2007 to add feature in Sharepoint.

Below article will showcase “How to restrict user to delete item from Sharepoint Library”. When user tries to delete any item, we will navigate them to Error page displaying custom message.
Restricting delete operation is a kind of feature we will add in Sharepoint. This feature will get deploy in via Feature.xml file and Elements.xml file.
What is Feature.xml?
This xml file will allow developer to deploy out-of-box feature onto Sharepoint 2007. This xml will allow performing the deployment without any coding. Feature.xml will define base property for a feature. It even reference all elements defined in sharepoint  Any feature can be turn on/off by activating and de-activating feature via sharepoint commands. Hence, feature.xml file can be used extensively in Sharepoint.
Note: Please perform below steps on server where sharepoint is deployed and running.
Below .Net code will help us to detect event during delete operation and help us to display custom error message. Open your new C# project and add below code to your class file.
namespace ItemDeletingHandler
{
    public class ItemDelete:SPItemEventReceiver   
    {
        public override void ItemDeleting(SPItemEventProperties properties)
        {
            properties.Cancel = true;
            properties.ErrorMessage = "Deleting items from " + properties.RelativeWebUrl + " is not supported.";
        }
    }
}
Here, you need to inherit from SPItemEventReceiver inbuilt class which will help you to detect event when some action occurs on your document library. You need to override ItemDeleting method. Build your project for any compile errors.
Signing DLL with strong key:
We need to refer DLL to Sharepoint. For this we need to GAC DLL. For gacing, DLL must have strong name. VS 2005 help to sign DLL with strong name. Follow below steps in VS 2005:
Move to Project -> “Project Name” Properties -> Signing tab,






















Deploying DLL in GAC.
Now, you can Build your solution: Build -> Build Solution. Now, your DLL is sign with strong key. Go to your project debug/Release folder and Drag and drop your DLL to GAC (C:\Windows\assembly).

Here, everything related to coding is completed. Now, we have to deal with XML files (to add features) and Command prompt (to activate features).

Creating project name folder in server
Every sharepoint features are found in Sharepoint Features folder (C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES). As we are activating sharepoint feature manually, so we need to create our feature folder in this folder, so sharepoint command’s can refer it during activation. Follow below steps:
1.       Navigate to above folder.
2.       Create folder with .Net solution name (in our case its ‘ItemDeletingHandler’)
3.       Create Feature.xml and Elements.xml file.
4.       Refer below section to add content in Feature.xml and Elements.xml file.

Feature.xml
Feature.xml file will include base properties for feature. This xml file will also refer few supporting file like xml, pdf, doc etc. In our case, its Elements.xml file. Add below code to Feature.xml file:
  
<Feature
   Scope="Web"
   Title="Deleting Event Handler"
   Id="7D1AE945-1E28-4224-AC60-B6FCB49DDF5E"
   xmlns="http://schemas.microsoft.com/sharepoint/">
   <ElementManifests>
      <ElementManifest Location="Elements.xml"/>
   </ElementManifests>
</Feature>

Scope: It refer to the scope of feature and within this scope, feature will be bind. Scope could be: “Farm”, “Web application”, “site collection”, “site”. In our case, its Web application, so we can use this feature to any Document Library in this web application.

Title: Title of this feature, as shown in MOSS.

ID: Every feature must be identify uniquely by sharepoint. You can generate GUID via VS 2005 – Tools -> Create GUID -> copy or generate new GUID and then copy it to clip board memory.

Xmlns: This is mandatory field require during activating feature in xml.
Element Manifests: It will refer to another xml file which actually gives all information about assembly.

·         Elements.xml
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
   <Receivers ListTemplateId="104">
      <Receiver>
         <Name>DeletingEventHandler</Name>
         <Type>ItemDeleting</Type>
         <SequenceNumber>10000</SequenceNumber>
         <Assembly>ItemDeletingHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5500998af4e34cf5</Assembly>
         <Class>ItemDeletingHandler.ItemDelete</Class>
         <Data></Data>
         <Filter></Filter>
      </Receiver>
   </Receivers>
</Elements>
ListTemplateID: Every elements in sharepoint has given unique IDs. So whatever elements we are targeting for event detecting, we should specify their ID. In our case, we are referring Document library whose id is ‘104’.
Assembly: You can refer assembly name and public key token name from GAC.
Class: It should be Namespace.Classname.

Installing and Activating feature in Sharepoint
We can activate features in feature.xml file with 2 methods: Command prompt and object model. We will only cover Command prompt as of now.
Open command prompt on your server and write below command

  1. stsadm -o installfeature -filename ItemDeletingHandler\Feature.xml
  2. stsadm -o activatefeature -filename ItemDeletingHandler\Feature.xml -url http://Server/Site/Subsite
  3. iisreset
Note: Underline words in command prompt are built in and mandatory. While not underlined words will get changed based on your project name. URL should be your site URL where you will activate this feature.

Now, you can refer to your site. Upload document to your site Document Library and try to delete the document. User should be navigate to Error page with message: “"Deleting items from http://Server/Site/Subsite is not supported."”

Hope this article helps you. Let me know your feedback on this. You can leave your comments for any queries. Cheers


Sharepoint Issues and Fixes

Below are Sharepoint 2007 issues I came around during my Sharepoint career. These issues we encounter in day-to-day scenerious. Check it out and let me know your feedback on this. Your feedback would be crucial which can soar my motivation to post more and more Sharepoint article on this blog and can help people to get their work done in minimal time.
I will keep appending issues/problems in Sharepoint along with their solution on this page. Keep Rocking !
  1. Failed to connect to an IPC Port: Access is denied.