Friday, December 9, 2011

Implementing Today function and Outstanding days


To use Today function in your SharePoint calculated column, you need to create a dummy column named as "Today" and then you can create a calculated column named as "Current Date". In the custom formula section of "Current Date" write =Today and save.Then Delete the Today column that you had created first. Your Current Column will now show you the Current Date system date.

If you are calculating the outstanding Days for an item since it is Date Opened then you can create custom column and write a formula for that like below:

=DATEDIF([Date Opened],IF(NOT(ISBLANK([Date Closed])),[Date Closed],[ Current Date]),"D")

This formula will calculate the No. of days for an item since Date Opened. 



Monday, November 21, 2011

Using Active Directory to Authenticate


Active Directory is a directory service acquainted by Microsoft to replace the senescent windows NT 4.0 domain architecture. It serves as a primal security point for controlling access to the resources with in the network. If you want to know more about the AD object structure visit Microsoft site (http://www.microsoft.com/technet/prodtechnol/windows2000serv/technologies/activedirectory/default.mspx)

Active Directory Service Interface (ADSI)
Active Directory Services Interface (ADSI) is a single interface from Microsoft which abstracts the capabilities of directory services from different providers so that the same interface can be used regardless of the environment.

Want to know more about ADSI.
(http://www.microsoft.com/windows2000/techinfo/howitworks/activedirectory/adsilinks.asp)

Authenticating our credentials
Authenticating our credentials using active directory is pretty simple.
Microsoft .Net framework includes a System.DirectoryServices namespace contained in System.DirectoryServices.dll. This dll is not added by default when you open a new webapplication project. This dll must be added manually as a reference in order to use it. It contains DirectorySearcher and DirectoryEntry class. These classes uses ADSI to interact with and manipulate the directory with in the managed code. The first step in doing any thing with the directory services is to create a connection . You can store the path in a string as shown ( string path = "LDAP://your domain ";)
Now only thing left to bind to the directory is to pass the path as a parameter to the constructor of a new instance of DirectoryEntry Class.

DirectoryEntry entry = new DirectoryEntry(path,Username,password);

DirectoryEntry Class can be used to authenticate a username and password against active directory. You can force authentication to occur by retrieving the nativeObject property.

string path = "LDAP:// your domain ";
string userName = domain + @"\" + txtUserName.text;
string password = txtPassword.text;
DirectoryEntry entry = new DirectoryEntry(path, userName , password);

try
{
// Bind to the native object to force authentication to happen
Object objnative = entry.NativeObject;
// "User authenticated" Move to the next page.
}
catch( Exception ex )
{
throw new Exception("User not authenticated: " + ex.Message);
}

That's it.. If you do this much , the username and password will be validated against ActiveDirectory.

Monday, October 17, 2011

Configuring SharePoint 2010 to return pdf files in search results


If you’ve configured PDF for Search in SharePoint 2007 then you are certainly almost there in getting it to work with SharePoint 2010. The process is almost identical with some minor changes due to service name change and directory changes. Below are the steps to get iFilter working and configuring pdf files search in a SharePoint 2010
IFilter Install
1.       Download PDF iFilter 9.0 for x64 platformshttp://www.adobe.com/support/downloads/detail.jsp?ftpID=4025
2.       Stop the IIS Admin Services by issuing IISRESET /Stop
3.       Install the iFilter (this needs to be on the index server)
4.       After the installation is complete restart IIS.
Add PDF icon to SharePoint.
1.       Find your favorite PDF icon and size it to your requirement if you don’t have one you can download one from
2.       Copy the icon to SharePoint 2010 Images directory C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\IMAGES
3.       Add the icon mapping into SharePoint icon mapping DOCICON.XML file located in C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\XML
As follows 
4.       Add pdf as a new search file type in SharePoint Search Services in yourApplication Management in Central Administration.
5.       If the installation and mapping were performed correctly, a pdf icon should appear after adding the File Type
Making changes to the registry
1.       Add the following registry entry as shown below, and then set the registry entry value to pdf HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\Search\Applications\\Gather\Search\Extensions\ExtensionList\
To add this entry, follow these steps:
1.       Click Start, click Run, type regedit, and then click OK.
2.       Locate and then click the following registry subkey:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\Search\Applications\\Gather\Search\Extensions\ExtensionList
3.       On the Edit menu, point to New, and then click String Value.
4.       Type 48, and then press ENTER.
5.       Right-click the registry entry that you created, and then click Modify.
6.       In the Value data box, type pdf, and then click OK.
2.       Verify that the following two registry subkeys are present and that they contain the appropriate values. If they are not present, you can manually create them
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\Search\Setup\ContentIndexCommon\Filters\Extension\
Verify .pdf subkey exists, if it doesn’t right click on Extensions and create aSubkey
3.       If the subkey exists, verify that it contains the following registry entries if not you can mod them to the subkey.
(StringValue) – Entry type when creating a new one
Name: Default
Type: REG_MULTI_SZ
Data: {4C904448-74A9-11D0-AF6E-00C04FD8DC02}
Verify these entries also exists, if not you can create them manually also.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\Search\Setup\Filters\.pdf
This registry subkey must contain the following registry entries:
(StringValue) – Entry type when creating a new one
Name: Default
Type: REG_SZ
Data: (value not set)
(StringValue) – Entry type when creating a new one
Name: Extension
Type: REG_SZ
Data: pdf
(DWord) – Entry type when creating a new one
Name: FileTypeBucket
Type: REG_DWORD
Data: 0x00000001 (1)
(StringValue) – Entry type when creating a new one
Name: MimeTypes
Type: REG_SZ
Data: application/pdf
4.       Once this process is completed, upload pdf documents on your SharePoint 2010
5.       Stop and start the SharePoint Search Service using the following commands fromthe command prompt. Remember administration privileges are required to perform this step.
Net Stop OSearch14
Net Start OSearch14
6.       Perform a full crawl, and your pdf files should be available in search results.

How to modify a DateTime value of AfterProperties in ItemUpdating/ ItemAdding Events in SharePoint


Issue Description:
  1. When you change the value of the DateTime column of Custom List in SharePoint's SPItemReceiver AfterProperties/BeforeProperties you need to set it to a specific DateTimeFormat string or else it throws the Error
  2. Error "Invalid date/time value. A date/time field contains invalid data. Please check the value and try again."
Steps to REPRO the Issue:
  1. Created a SharePoint Customer List
  2. Add a new custom Column of type DateTime (Example: ApprovedTimeStamp)
  3. Created a Feature Receiver Event Handler Assembly implementing ItemUpdating/ ItemAdding event.
    (Note: EventHandler sample showing ItemUpdating code is attached in the blog)
  4. Try to assign value to the Datetime Column of After Properties in ItemUpdating/ ItemAdding event. If you assign value either of the below mentioned way it throws Error: "Invalid date/time value. A date/time field contains invalid data. Please check the value and try again."
  5. properties.AfterProperties["ApprovedTimeStamp"] = DateTime.Now ;    //Generates Error
    properties.AfterProperties["ApprovedTimeStamp"] = DateTime.Now.ToString();   //Generates Error
    properties.AfterProperties["ApprovedTimeStamp"] = new DateTime(2008, 11, 08) ;   //Generates Error
    properties.AfterProperties["ApprovedTimeStamp"] = DateTime.Now.ToLongDateString();   //Generates Error 
    properties.AfterProperties["ApprovedTimeStamp"] = DateTime.Now.ToShortDateString();   //Generates Error
Resolution / WorkAround:
When setting a DateTime value in AfterProperties you have to convert the the DateTime to an ISO8601 string format. Either of the below mentioned line can be used to assign value to DateTime Column of Afterproperties in ItemUpdating/ ItemAdding Event:
  1. properties.AfterProperties["ApprovedTimeStamp"] = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssZ");    // Works Fine
  2. properties.AfterProperties["ApprovedTimeStamp"] = Microsoft.SharePoint.Utilities.SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Now);    // Works Fine

sharePoint 2010 – Enable & using Developer Dashboard


How to enable Developer Dashboard and how to use this?
Enable / Disable over stsadm:
stsadm –o getproperty –pn developer-dashboardget the current setting from developer dashboard (On |Off | OnDemand )
image
stsadm –o setproperty –pn developer-dashboard –pv “OnDemand”set the setting from developer dashboard (On |Off | OnDemand)
image
Enable / Disable over powershell (functionality has changed in beta time)
OLD: Turn On: Set-SPFarm –DeveloperDashboardEnabled
OLD: Turn Off: Set-SPFarm –DeveloperDashboardEnabled $false
NEW: Turn On: for onDemain Mode
$service = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$addsetting =$service.DeveloperDashboardSettings
$addsetting.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::OnDemand
$addsetting.Update()

NEW: Turn On
$service = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$addsetting =$service.DeveloperDashboardSettings
$addsetting.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::On
$addsetting.Update()

NEW: Turn Off
$service = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$addsetting =$service.DeveloperDashboardSettings
$addsetting.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::Off
$addsetting.Update()

Details see here: SPDeveloperDashboardLevel EnumerationDeveloperDashboardSettings
Mode of developer dashboard:
On – creates everytime the output at the end of the page content
Off – switch off developer dashboard and nothing is rendered
OnDemand – creates a DeveloperDashboard icon to make dashboard output visible as needed
image
example of an oob publishing page
Now with the next Page Load, the troubleshooting output is created:
DeveloperDashboard Icon is displayed at the upper right side
image(exist only in OnDemand-Mode)
image
How to use the Developer Dashboard?
Developer dashboard is designed to find performance bottleneck during the page load.
To get an overview about the whole page load performance take a look in the upper right side  on category “web server”. On my test environment the total time of page rendering  is 438.79 milli seconds.
image
At the left side you will see the ASP.NET rendering process of all involved controls with their time to render. Here is makes sense to focus only on long running controls.
image
In this case the longest operation is “EnsureListItemsData with 293,34 ms)
Because sharepoint controls will request data from database, the developer dashboard lists also corresponding sql requests with their execution time.
image
If you click on the sql command than a popup windows display more details. The long running sql request on my test environment is “Declare @…”
image
During this request i see the complete SQL query and the corresponding call stack to identify the correct control. Additionally at the end we see the IO Stats in case of a slow running SQL server based on too many IO-operations. 
One additional category exist for webparts to identify the slow running ones. In this case the ListView-Webaprt of the “Shared Document Library” is the slowest one.
image

Wednesday, April 20, 2011

Workflows do not start in SharePoint

You are of course aware of the fact that starting with Service Pack 1 the workflows created in SharePoint designer that should launch under the credentials of the system account will no longer start automatically.




You know what the resolution is for this problem: simply do not to use the system account.



You implemented all the steps written here http://support.microsoft.com/kb/947284 ,but the workflow still does not start.



More interesting, if you email-enable a document library and attach a workflow to it, and set the workflow to start on Item creation, this workflow will never start.



This usually happens because the e-mail is saved into the document library using the sharepoint services timer service account credentials. If an e-mail was created by the system account then the workflow will attempt to start using the system account which is no longer permitted.



As you cannot change the credentials for the for the timer service, what should you do?



The answer is pretty simple: install Infrastructure Update http://support.microsoft.com/kb/953749/(and of course if you are at it, you can update the whole farm to the latest patch level (FEB CU) ) and pay close attention to one small line (made bigger here because of it’s importance) written in the notes part of the knowledgebase article:



To prevent the declarative workflows from impersonating the system account, the workflows will now impersonate the user who created the workflow association.



This basically means that you should create a special account not SHAREPOINT\SYSTEM, that is a site collection owner on the site collection where the workflow is hosted, open the workflow in SharePoint Designer while logged on as this new account and simply save the workflow without modifying anything.



It will effectively change the account that associated the workflow, which will allow it to start.



A !



you should also run



stsadm -o setproperty -pn declarativeworkflowautostartonemailenabled -pv true



to enable workflows to start using the impersonation scheme



Monday, May 17, 2010

Differences between site definition and site templates

Site Template
The first option for getting the SharePoint Designer changes beyond the current site is to take the site you've modified with SharePoint designer and save it as a template. Then when you need a new site you create it from the site template you've created. This approach works but it means that you either have to create a new site template for each of the built in site definitions -- or you have to live with just the one site template that you've created. It also means that you can't go back and apply the changes after they've been created.Finally, to add insult to injury, if you ever change the work that you did on the original site those changes won't be reflected across the other SharePoint sites that were created from the template because each page exists separately in the database. So site templates solve the problem of getting SharePoint Designer changes into multiple sites but without the ability to adapt to changes in the future.
Site Definitions
solve the problem of site templates in that changes can be affected to them after they've been created -- but at the cost of additional work. Site definitions exist on the file system of each of the front end web server unlike site templates which exist in the content database. Each site which is created from the site definition doesn't make a copy of the page in the database, instead it stores a pointer to the site definition file. The good news is that when the page on the file system changes it changes all of the references in the database -- thus solving the problem of making changes to existing branding.In order to do a site definition, you'll first have to get the changes to the files that you want into files. You can do this from SharePoint Designer by selecting Save As and pointing to a directory. From there you have to create the support files for the site definition including the ONET.XML file which drives how the site definition is used, and the WEBTEMP*.XML file which makes the site definition show up as an option. In most cases you'll copy the STS site definition that comes with SharePoint and make your changes there rather than starting from scratch.

Pros and Cons of Site Definitions and Site Templates.
Customization of site definitions holds the following advantages over custom templates:
-Data is stored directly on the Web servers, so performance is typically better.
-A higher level of list customization is possible through direct editing of a SCHEMA.XML file.
-Certain kinds of customization to sites or lists require use of site definitions, such as introducing -new file types, defining view styles, or modifying the drop-down Edit menu.
Site definition disadvantages include the following:
-Customization of site definition requires more effort than creating custom templates.
-It is difficult to edit a site definition after it has been deployed.
-Doing anything other than adding code can break existing sites.
-Users cannot apply a SharePoint theme through a site definition.
-Users cannot create two lists of the same type with different default content.
-Customizing site definitions requires access to the file system of the front-end Web server.
-Custom templates hold the following advantages over customization of site definitions:
-Custom templates are easy to create.
-Almost anything that can be done in the user interface can be preserved in the template.
-Custom templates can be modified without affecting existing sites that have been created from the templates.
-Custom templates are easy to deploy.
Custom template disadvantages include the following:
-Custom templates are not created in a development environment.
-They are less efficient in large-scale environments.
-If the site definition on which the custom template is based does not exist on the front-end server or servers, the custom template will not work.