Learning SharePoint
Friday, December 9, 2011
Implementing Today function and Outstanding days
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
How to modify a DateTime value of AfterProperties in ItemUpdating/ ItemAdding Events in SharePoint
Issue Description:
- 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
- Error "Invalid date/time value. A date/time field contains invalid data. Please check the value and try again."
- Created a SharePoint Customer List
- Add a new custom Column of type DateTime (Example: ApprovedTimeStamp)
- Created a Feature Receiver Event Handler Assembly implementing ItemUpdating/ ItemAdding event.
(Note: EventHandler sample showing ItemUpdating code is attached in the blog) - 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."
- 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
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:
- properties.AfterProperties["ApprovedTimeStamp"] = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssZ"); // Works Fine
- 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:
Enable / Disable over powershell (functionality has changed in beta time)
OLD: Turn On: Set-SPFarm –DeveloperDashboardEnabledMode of developer dashboard:
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 Enumeration, DeveloperDashboardSettings
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
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
How to use the Developer Dashboard?(exist only in OnDemand-Mode)
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.
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.
Because sharepoint controls will request data from database, the developer dashboard lists also corresponding sql requests with their execution time.
In this case the longest operation is “EnsureListItemsData with 293,34 ms)
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 @…”
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.
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.
Wednesday, April 20, 2011
Workflows do not start in SharePoint
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
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.