Saturday, February 18, 2012

CAML Query Where Criteria for Boolean type columns

Interestingly enough, boolean type columns can either be used as Integer or Boolean values and heres how its done.
string CAMLQuery = "<Where> <Eq><FieldRef Name='Online'/> <Value Type='Integer'>1</Value></Eq> </And> </Where>" ;
or
string CAMLQuery = "<Where> <Eq><FieldRef Name='Online'/> <Value Type='Boolean'>True</Value></Eq> </And> </Where>" ;
where TRUE, True, true are all possible values

CAML Query Where Criteria for Date type columns and date formats

When I started writing a CAML query which involved checking against a certain date in a date time type column in one of my list, I thought that it would be as simple as

string CAMLQuery ="<Where>"+ "<And>"+ "<Leq>FieldRef Name='Start_x0020_Date'/>"+ "<Value Type='DateTime'>" + DateTime.Now + "</Value></Leq>"+ "<Geq><FieldRef Name='End_x0020_Date'/>"+ "<Value Type='DateTime'>" + DateTime.Now + "</Value></Geq>"+ "</And>" + "</Where>";

assuming that it will return me results where Start Date is less than today and End Date is greater than today meaning that everything that needs to be shown today will come up but as it turned out it was not the case.
CAML Queries expects a certain datetime format when it comes to use them in WHERE Clauses.
You can use a complex

SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Now)

or you can use

String.Format("{0:s}", DateTime.Now)

which results in

string CAMLQuery ="<Where>"+ "<And>"+ "<Leq>FieldRef Name='Start_x0020_Date'/>"+ "<Value Type='DateTime'>" + String.Format("{0:s}", DateTime.Now) + "</Value></Leq>"+ "<Geq><FieldRef Name='End_x0020_Date'/>"+ "<Value Type='DateTime'>" + String.Format("{0:s}", DateTime.Now) + "</Value></Geq>"+ "</And>" + "</Where>";

One of the solutions I found on internet was to use an Offset, something like

string CAMLQuery = "<Where> <Geq> <FieldRef Name='MyDateColumn' /> <Value Type='DateTime> <Today OffsetDays='-5' /> </Value> </Geq> </Where>";

which means 5 days less than today.
You might also be interested in IncludeTimeValue attribute which can a TRUE or a FALSE value

Tuesday, May 31, 2011

Javascript replace function

As the name implies, replace function searches a string for a particular substring provided as a function parameter and replaces it with the desired string.
Example No. 1
var tempStr = "replace function is not working";
document.write(str.replace("not working", "working"));
Result tempStr = replace function is working

However one problem with replace function is that it only replaces the first substring found.
Example No. 2
var tempStr = "a1b1c1d1e1f1";
document.write(str.replace("1", "+"));
Result tempStr = a+b1c1d1e1f1

We need something like replaceAll function in this situation. replaceAll function doesnot exists but we have a work around.

Example No. 3
var tempStr = "a1b1c1d1e1f1";
tempStr = tempStr.replace(new RegExp("1", 'g'),"+");
Result tempStr = a+b+c+d+e+f+

Thursday, May 26, 2011

Open window in a new browser

There are times when you want to open web page in a new window/browser using Javascript. Before we discuss javascript solution, let me share other ways as well to open new pages using clientend.
It cant get any simpler than this
To view all my post, pleace click here
Code <a href="http://www.qaziarfeen.blogger.com" >here </a>
Code <a href="http://www.qaziarfeen.blogger.com" target="_blank" >here </a>

Using Button
Instead of hyperlinks, we can use HTML buttons as well and make them behave the same way as hyperlinks

Use the following code to test the behaviour to open page in the same window

<input id="btOpen1" type="button" value="Home" onclick="return ClearUrl();" />

<script type="text/javascript" >
function ClearUrl() {

window.location.href = "www.google.com";
}
</script>



Use the following code to test the behaviour to open page in a new window
<input id="btOpen1" type="button" value="Home" onclick="return ClearUrl();" />
<script type="text/javascript" >
function ClearUrl() {
window.open('http://qaziarfeen.blogspot.com'_blank');
}
</script>

Wednesday, May 25, 2011

Email Notification Delays in SharePoint 2007

I was observing delays in notification email being received when I assign a task to someone using SharePoint Task.
I have already post on how to resolve it in SharePoint 2010. Here is a revision again


The timer interval service which sets this delay is called "job-investigation-alerts" This service send notifications out. The default timer interval is 5 minutes but we can of course change it using stsadm command

Open command prompt and browse to 12\bin and run the following command to identify if the job is running on the site



stsadm -o getproperty propertyname job-immediate-alerts -url < your-site-URL >


If you get Property Exists="Yes" and Value as some value defining the interval configured, it means that the service is running and you can change the interal using the following command

To set the property run the following command



stsadm -o setproperty -propertyname job-immediate-alerts -propertyvalue < A valid Windows SharePoint Services Timer service schedule > -url < your-site-URL >


Property Value can be set in the following manner


stsadm -o setproperty -propertyname job-immediate-alerts -propertyvalue "every 1 minutes between 0 and 59"


By running the above command you set the job to run every minute


References:

Tuesday, April 19, 2011

HTML iframe tag

iframe or inline-frame can be added to your html in the following way. <iframe src="http://www.google.com"> </iframe>
Other attributes of IFRAME are


align: left; right; top; middle; bottom
Deprecated. Use styles instead.Specifies the alignment of an iframe according to surrounding elements
height: pixels; %
Specifies the height of an iframe
name: name
Specifies the name of an iframe
scrolling: yes; no; auto
Specifies whether or not to display scrollbars in an iframe
src: URL
Specifies the URL of the document to show in an iframe
width: pixels; %
Specifies the width of an iframe



Reference http://www.w3schools.com/

Monday, April 11, 2011

How to delete a Document Library in SharePoint

Deleting a document library or any list is very simple in SharePoint implies you have required permissions to perform the operation.
In SharePoint 2007 (MOSS 2007)

1. Go to the site where your library resides.
2. Click Site Actions>View All Site Settings 3. Click the Document Library that you want to delete. Once on the AllItems.aspx page of the library, select Document Library Settings from Settings Menu.

4. Under Permission and Management, click Delete this document library. 5. Once you click Delete this document library link, a confirmation will be poped up informing you that all the contents of this library will be deleted and sent to Recycle Bin of the site (depending on your deletion policy).
6. Press OK to delete the library.

In SharePoint 2010
1. Open SharePoint site on which your document library resides which you want to delete.
2. Click Site Actions> View All Site Contents menu.
3. Click the Document Library that you want to delete.
4. On the Library Tools tab, click Library.
5. On the Library tab under the Settings group, click Library Settings.
6. Click Delete this document library on the Document Library Settings page under Permissions and Management.
7. Click OK to confirm your action.