Monday, September 22, 2008

DateTime in CAML Query

Caml query not using the time part in datetime. If your are doing a caml query and you see that your time is being ignored in datetime try this:

<Value Type=”DateTime” IncludeTimeValue=”TRUE”><Today /></Value>

You have to use IncludeTimeValue=”TRUE”.

You can use greator or equal like above and less or equal filter with AND operator in CAML above to work with date range.

If the date value is coming from your variable etc then you need to use SPUtility function and get the string required by CAML for date time variable.

DateTime CustomDate = DateTime.Now;
string strCustomDate = SPUtility.CreateISO8601DateTimeFromSystemDateTime(CustomDate);

This CAML Query below return the items based on MyDate with less than 10 days.
Basically using a Greator or Equal operatior and providing Today date - 10 days as a filter.

<Query>
<Where>
<Geq>
<FieldRef Name="MyDate" />
<Value Type="DateTime">
<Today OffsetDays="-10" />
</Value>
</Geq>
</Where>
</Query>

Saturday, September 20, 2008

SPListItem.Update() throws error Operation is not valid due to the current state of the object.

Problem:
When running SPListItem.Update commands inside SPSecurity.RunWithElevatedPrivileges block in the .net application in the sharepoint virtual directory environment then you get error: Operation is not valid due to the current state of the object.

When you can add the procedure in the SPSecurity.RunWithElevatedPrivileges block then some time also Call Stack error has occured.
When you can install your webpart or Usercontrol in the sharepoint page then this type error is not occurred.
Instead you should instantiate the SPSite or SPWeb there and call Update afterwards.

Monday, September 15, 2008

Get Public Key Token(PKT) in VS 2005 for signed assembly

Here is the easiest way to get public key token in the vs 2005.
1. In Visual Studio 2005, click Tools -> External Tools...
2. Click Add and enter the following into the different fields.
* Title: Get Public Key
* Command: C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sn.exe
* Arguments: -Tp "$(TargetPath)"
* Uncheck all options, except Use Output window\

How to Restrict access to MOSS Web Services?

Here is the methode for restrict access to web services in the MOSS.

In order to restrict that we can add an entry in web.config file of that Site Collections web application.
Add the following block

<location path="_vti_bin">
<system.web>
<authorization>
<allow users="sps\user" />
<deny users="*" />
</authorization>
</system.web>
</location>






Thursday, September 11, 2008

Forms authentication and SharePoint Designer

The SharePoint designer always works with Windows authentication mode only. So, if you have converted your site to use forms authentication, you will not be able to open in the designer.

Hence, even if you are going to have an Internet facing site, the best practice would always be to have your default zone site with windows authentication and extend this for the Internet zone.

Steps to do this is available all around the place, check this for a start.

http://technet.microsoft.com/en-us/library/cc262668(TechNet.10).aspx

Wednesday, September 10, 2008

Maximum Versions Settings on Lists and Document Libraries


Versioning is a powerful feature of SharePoint-based lists and document libraries.

In document library and list,every time when change the item then it taks extra sizes so database size is increase.
Many organizations may wish to limit the amount of major versions that are kept.
However, this setting is determined by each individual list - but one can easily change this setting via the WSS.
Here is the programatically you can change the limit of the maximum version through the event handler or in your webpart.

public void VersionSettingLimit(string siteUrl)
{

SPSite site = new SPSite(siteUrl);
SPWeb web = site.OpenWeb();
web.AllowUnsafeUpdates = true;
SPListCollection listColl = web.Lists;
foreach (SPList list in listColl)
{
try
{
list.MajorVersionLimit = 2;
list.Update();
}
catch (Exception setVersionException)
{
}
}
}