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.

Monday, March 21, 2011

SharePoint Error: The path specified cannot be used at this time. Exception from HRESULT: 0x80070094

I was trying to create a new Site Collection on MOSS 2007 for one of my client's UAT environment when I got this error.
The path specified cannot be used at this time. Exception from HRESULT: 0x80070094.

On Microsoft Windows Server 2003 R2 Enterprise Edition with Service Pack 2 and MOSS 2007, I performed the following actions

1.
Restart IIS
Click Start > Run
Type cmd and press Enter
Run command iisreset


2.Restart SharePoint Timer Service
Right click My Computer
Click Manage
Expand Services and Application
Click Services Restart Windows SharePoint Services Timer (Service Name SPTimerV3)


3.Restart Server (I didnot perform this action but it always works with Microsoft :)

Tuesday, February 22, 2011

How to Delete/Remove a Workflow from SharePoint Designer

When you create a workflow from SharePoint Designer, it is always attached to a single list of library. They just cannot be reused.

Removing a workflow is a two fold thing means if you just want to make the workflow unavailable to users or actually deleting it.

Removing a workflow through a browser does not actually delete it.

If a workflow is created through SharePoint Designer and removed through a browser, it just gets unavailable to users but all the source files used to compile a workflow remains stored in Workflow Document Library of the site.


To remove a workflow, follow these steps

1. Browser to the list which you want the workflow to be removed from.

2. On the list library menu bar, click Settings and then click List Settings

3. You will end up on page where you can customize your list. Under Permissions and Management, click Workflow Settings

Note: If you have a workflow associated with this list, you will see the list of workflows added and will be given an option to remove or add another workflow but if there is no workflow attached, you will be directed to "Add a workflow" page from where you can create Out of the Box workflows.

4. If you have workflows attached to your list, you are on Change Workflow Settings Page, click Remove a workflow hyperlink.

5. You will be provided with a list of workflows that are associated with the list. Click Remove radio button against the workflow that you want removed.

6. Click OK

Note: There is a difference between No New Instance and Remove. If you remove a workflow from a list by selecting Remove option, it will cancel all the running instances of the workflow. If you want to keep the current instance running, select No New Instance. This will help you complete the already instance and in the meantime will not allow any new action to be performed from the workflow that you want removed. Once all the instances are complete, you can come back to this screen and remove the workflow.


To delete a workflow, follow these steps

Deleting a workflow from SharePoint Designer is simple and as discussed earlier, deleting a workflow from SharePoint Designer will delete all the source files from the site and will stop all the workflow instances that are currently running on the list or library.

1. Open your site in SharePoint Designer.

2. From the Folder List Pane on the left of your SharePoint Designer, expand Workflows Folder

Note: If Folder List is not visible, click View>Folder List to make it visible.

3. Select the workflow that you want to delete and press Delete button on the keyboard. A confirmation message will be shown to you to confirm if you actually want to delete it, click Yes

Note: You can select multiple workflows by clicking workflows and holding CTRL key.



How to enable SharePoint Designer Workflows

We know that there are 3 types of workflows


  • Out of the box workflows

  • SharePoint Designer workflows

  • Custom workflows using Visual Studio and Workflow Foundation (WF)

By default SharePoint Designer workflows are enabled on a site in SharePoint 2007 (MOSS) but if you want to change the default settings (or if they are disabled) follow these steps



  1. Open Central Administration.

  2. Click Application Management tab.

  3. Under Workflow Management Section, click Workflow settings.

  4. Make sure you have selected the web application on which you want to perform the operation

  5. Click Yes or No for "Enable user-defined workflows for this site?" depending on your requirement.

Note: Users with Web Designer permissions can create and deploy workflows by using the Workflow Designer wizard in Office SharePoint Designer 2007.

Wednesday, February 16, 2011

CAML Query and Where Clause Examples

Here I will try to cover as many combinations of Where Clauses as I can.
I will also explain each of them a little. Keep visiting this post for more examples.


EQ: If you notice here, we don't have any "=" (equals to) sign. We have our equals to criteria wrapped inside EQ Tag.
<Where>
<Eq>
<FieldRef Name='Title'/>
<Value Type='Text'>Hello World</Value>
</Eq>
</Where>

AND: If we want to have data with a criteria which involves 2 or more column and a AND condition, this is how it looks in CAML. Notice we have all criteria nested inside AND
<Where>
<And>
<Eq>
<FieldRef Name='Title'/>
<Value Type='Text'>Hello World</Value>
</Eq>
<Eq>
<FieldRef Name='Column2'/>
<Value Type='Text'>CAML</Value>
</Eq>
</And>
</Where>

OR: OR schema is same as AND
<Where>
<Or>
<Eq>
<FieldRef Name='Title'/> <Value Type='Text'>Hello World</Value>
</Eq>
<Eq>
<FieldRef Name='Title'/><Value Type='Text'>Bye World</Value>
</Eq>
</Or>
</Where>

Greater Than: Any such operator can be used with or without AND/OR Clause
<Where>
<Gt>
<FieldRef Name='Age'/><Value Type='Text'>18</Value>
</Gt>
</Where>

Less Than: Any such operator can be used with or without AND/OR Clause
<Where>
<lt><FieldRef Name='Salary'/><Value Type='Text'>$5000</Value></lt>
</Where>

Order By: This clause is used independent of Where clause. If you do not define an order, default is ascending.
<OrderBy>
<FieldRef Name="Salary" Ascending="True"/>
<FieldRef Name="Age" Ascending="False"/>
<FieldRef Name="JoiningDate"/>
</Order>
<!--[if !supportLineBreakNewLine]-->
<!--[endif]-->

CAML Query SPQuery Object and Where Clause

To fetch data/item (SPListItem ) from SharePoint List (SPList) we have to use CAML with SPQuery class.
We have already discussed CAML in our last post, now we will look at SPQuery class and Where Clause in a bit of detail in this post.

SPQuery Class is used to hold query, attributes, fields and other important properties.
To fetch data from list, we need to call GetItems function of SPList class.

Here is how it should be done.

SPList list = web.Lists["List Name"];
SPQuery query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>Hello World</Value></Eq></Where>";

SPListItemCollection itemsCollection = list.GetItems(query);
GetItems of SPList class has 3 overloaded methods which takes SPQuery, SPList as arguments.
As SPListItemCollection is a collection which has SPListItem type items, we can access any item by either having a foreach loop or directly accessing an item by passing index.


CAML Query

CAML stands for Collaborative Application Markup Language. This language within the context of Microsoft SharePoint Services/Foundation to define query against list data.
To simplify things, as we have SQL to perform operations of SQL Server, we have CAML to perform operations on List.
Note: With SQL, we can perform a lot more complex operations which we cannot perform in CAML.

CAML is XML like structure with some of the schema elements defined below
WHERE <Where> </Where> Just like WHERE Clause in SQL but unlike SQL where we have WHERE mostly coming in last, here our query starts with a WHERE Clause.
AND <And> </And> Just like AND Clause in SQL but as explained above, its a XML like schema so every criteria has to be inside AND Tags.
OR <Or> <Or> Similar to OR Clause in SQL but XML like schema.
EQ <Eq> <Eq> Represents a "=" (Equals To)
NEQ <Neq> <Neq> Represents a "!=" (Not Equals To)
GT <gt > <gt > Represents a ">" (Greater Than)
LT <lt > <lt > Represents a "<" (Less Than)
FieldRef <FieldRef> <FieldRef> Can be considered as a column in SQL Server but with different attributes

A standard CAML QUERY
<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>Hello World</Value></Eq></Where>
More on CAML in next post

Tuesday, February 15, 2011

Programmatically add records in a List in SharePoint

using Microsoft.SharePoint;

SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite("SITE URL"))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["LIST NAME"];
web.AllowUnsafeUpdates = true;
SPListItem item = list.Items.Add();
item["TITLE"] = "Hello World";
item.Update();
list.Update();
web.AllowUnsafeUpdates = false;
}
}
});

Now for some explanation :

using Microsoft.SharePoint; This namespace is added at the start of the .cs file to use available classes. We have to first add a reference to Microsoft.SharePoint.dll file by right clicking your solutions/project/web application and selecting Add Reference option.
If you are working on SharePoint 2007 (MOSS) browse to 12 hive and then to ISAPI folder and select Microsoft.SharePoint.dll (C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\ISAPI). If you are working on SharePoint 2010, the folder is 14.

After adding reference importing the required namespace, we have a Security Context

SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite("SITE URL"))
{
using (SPWeb web = site.OpenWeb())
{
/
/do something there
}
}
});

If you are logged in as a user who does not have rights to perform any insert operation, we elevate privileges. This feature is provided in Windows SharePoint Services 3.0 to perform actions in code programmatically using an increased level of privilege.

using scope is introduced so that as soon as SPSite and SPWeb objects gets out of context, they are disposed of automatically

SPSite site = new SPSite("SITE URL")We first open the site in which we have the list on which we want to perform insert operation.

SPWeb web = site.OpenWeb()We open the web in which we have the list of which we want to perform insert operation.
SPList list = web.Lists["LIST NAME"];Now we create object of SPList Class with the list in which we have to perform insert operation. "LIST NAME" is the name of the list which needs to be accessed from your code.

web.AllowUnsafeUpdates = true; We get security validation errors if we do not set our web for AllowUnSafeUpdates.

SPListItem item = list.Items.Add();SPList class is collection of list items. Just like any other collection, say DataTable for instance, whenever we want to add a new item to collection, we call the Add method to return SPListItem object. Simply speaking, this object represents a row in the SPList list.

item["TITLE"] = "Hello World"; As we discussed above that SPListItem instance represents a row in your list, now you can access columns/fields and set valid values in them.

item.Update();
list.Update();
web.AllowUnsafeUpdates = false;After setting the values, we update our item, we finally update our list which inserts data in the list. We initially set web.AllowUnsafeUpdates to true to avoid errors. Now we are done with our insert operation, its better to set it to false again.
The code will automatically move to the next statement which is closing braces of our using block which disposes our SPWeb and SPSite objects.

Tuesday, January 25, 2011

How to identify which version of SharePoint you are using

It first seems obvious that you know what version of SharePoint you are using.
When I say version, I dont mean if you are using 2007 or 2010, I mean to say if you are using Express, Standard or Enterprise.

To find what version you are using in SharePoint 2007 (MOSS),
  • Go to Central Administration
  • Click Site Actions
  • Click Site Settings
  • Under Site Information you will see that version is installed

To find what version you are using in SharePoint 2010,
  • Run SharePoint 2010 Management Shell (Power Shell)
  • Run the command get-spfarm | Select Products
You will get all Products listed

For a complete list of Product GUID

SharePoint Foundation 2010: BEED1F75-C398-4447-AEF1-E66E1F0DF91E 
Search Server Express 2010: 1328E89E-7EC8-4F7E-809E-7E945796E511 
SharePoint Server 2010 Standard Trial: B2C0B444-3914-4ACB-A0B8-7CF50A8F7AA0 
SharePoint Server 2010 Standard: 3FDFBCC8-B3E4-4482-91FA-122C6432805C 
SharePoint Server 2010 Enterprise Trial: 88BED06D-8C6B-4E62-AB01-546D6005FE97 
SharePoint Server 2010 Enterprise: D5595F62-449B-4061-B0B2-0CBAD410BB51 
Search Server 2010 Trial: BC4C1C97-9013-4033-A0DD-9DC9E6D6C887 
Search Server 2010: 08460AA2-A176-442C-BDCA-26928704D80B 
Project Server 2010 Trial: 84902853-59F6-4B20-BC7C-DE4F419FEFAD 
Project Server 2010: ED21638F-97FF-4A65-AD9B-6889B93065E2 
Office Web Companions 2010: 926E4E17-087B-47D1-8BD7-91A394BC6196

Reference:

Monday, January 24, 2011

Windows Phone 7 Challenge

Dear Students,

Windows Phone 7 Challenge is a competition to help students discover and cultivate their interests in the areas of Windows Phone 7 compatible applications development technologies. The competition is very demanding and inspiring and Students are required to design and develop Windows Phone 7 compatible applications to address the theme: Imagine a world where technology helps solve the toughest problems. You can design and develop applications from scratch, or develop or improvise on known Windows 7 applications.

TO REGISTER:

Getting started is easy: In a four step procedure you will be eligible to participate in this competition:

Step one: Register yourself and your team (of up to four members).

Step two: Submit your Application Synopsis, which includes you XAP application, a short description of your team’s XAP application, including how it addresses the Theme Imagine a world where technology helps solve the toughest problems.

Step three: Submit your XAP Video following the outlined technical requirements and provide us the link to the video through the Contest Site, which should be uploaded on youtube. This Video should present your XAP application’s functionality or game play and provide an opportunity for your Team to explain the features as they are presented.

Step four: Your Team will present your XAP Application Source Code.

In round one, a team Pi Maxies from FAST National University of Computer & Emerging Sciences, Karachi won the contest. This proves that your participation will be nothing short of fruitful! Additional material is available on the contest site, including tools, e-books, help tutorials and videos.

PRIZES:

Register for this student technology contest, MEA Windows Phone 7 challenge and in reward stand a chance to visitMicrosoft Corporation for five days! Also, you gain real life experiences, make new friends and an opportunity to turn your ideas into reality! Other prizes for winning students include cool devices like Notebooks and Netbooks!

For detailed information on the competition, registration and rules and regulations, tools to get started and other related news go to the MEA Windows Phone 7 Challenge.

Warm Regards,

Business Lead

Microsoft | Innovation Center – Pakistan

Thursday, January 20, 2011

Planning guide for sites and solutions for Microsoft SharePoint Server 2010, Part 1

This book provides information about planning for deploying Microsoft SharePoint Server 2010. Subjects include site Security, Governance, and Enterprise Content Management. The audiences for this book are Business Application Specialists, Line-of-business specialists, Information Architects, IT generalists, Program Managers, and Infrastructure Specialists who are planning a solution based on SharePoint Server 2010. This book is part of a set of four planning guides that provide comprehensive IT planning information for SharePoint Server.
You can download the book by clicking here

AUC Technologies Offering Courses on Microsoft Technologies at Sir Syed University

AUC Technologies will held a seminar on many Microsoft Technologies at Sir Syed University of Engineering and Technology, Karachi, Pakistan on coming Sunday i.e. 23rd January 2010 from 9:00 AM - 1:00 PM.
Its an open invitation to all those who are interested for a 4 hour FREE Training.

Agenda:
  • Visual Studio 2010 SP1 and .NET Framework 4.0
  • ASP.NET 4.0, AJAX, ASP.NET MVC and LINQ
  • Silverlight and Windows Phone 7
  • SharePoint 2010
  • Augmented Reality
  • Entrepreneur and Blogging
  • SQL Server 2008 R2
Speakers:
  • Muhammad Atif Hussain
  • Shayar Javed
  • Usama Wahab Khan
  • Umema Adil
  • Mauhib Iqbal

The AUC Team would be glad to see you there.

Missing PDF Icon in SharePoint 2010

Notice when you upload a PDF file in document library of your SharePoint 2010 site, the icon is not there. SharePoint does not have the definition for icon of PDF files.

To get the document library show PDF or any other icons, follow these steps
  1. Open folder [drive]\Program Files\Common Files\Microsoft Shared\Web server extensions\14\Template\Images.
  2. Copy PDF icon in this folder. (You can get PDF icon from http://www.adobe.com/misc/linking.html. It is recommended to download 17 x 17' )
  3. Stop IIS by running iisreset/stop on command prompt.
  4. Open folder [drive]\Program Files\Common Files\Microsoft Shared\Web server extensions\14\Template\Xml
  5. Make a copy of DocIcon.xml file.
  6. Open DocIcon.xml and add < Mapping Key="pdf" Value="[Name-Of-Icon-File.gif]" />
  7. Save and close DocIcon.xml file.
  8. Start IIS again by running iisreset/start on command prompt.

Now go to your document library where you uploaded PDF file and verify the icon.


Note:
For SharePoint Portal Server 2003: Use 60 in place of 14
For SharePoint Portal Server 2007: Use 12 in place of 14

Open vs Save Dialog box in Document Library of SharePoint 2010

I uploaded some files in Document Library of my SharePoint 2010 site. When users clicked them, instead of opening them in browser, it gave them Save Dialog Box to save it to the local disk.

This was a surprise for me because SharePoint 2007 (MOSS) has this feature. Microsoft SharePoint 2010 says that it has closed this option intentionally as there are security threats as there is a possibility that some unwanted code snippets are uploaded in the document.

To solve this problem
  1. Go to Central Administration
  2. Click Manage Web Applications
  3. Select the web application for which you want to change the default behavior
  4. Click General Settings from the top ribbon
  5. Scroll down to Browse File Handling
  6. Change the option from Strict to Permissive
  7. Click OK

Now go to document library of the site again and test the new behavior.


Email Notification Delays in SharePoint 2010

I was having problems when my custom made Visual Studio workflow initiated a task. The problem was that I was getting email notifications at least after 5 minutes. I had every thing configured perfectly. The problem is not only related to custom workflows, the original issue was that any notification being sent either from lists, Announcements, Alerts were delayed.

Upon investigation, I found out that there is a job in Sharepoint 2010 called "job-immediate-alerts"
which is by default configured to run every 5 minutes.

As stated my Microsoft it specifies the frequency to check for alerts that are to be sent immediately. The value specified is in minutes.

Open command prompt and browse to 14\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 >


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:
http://technet.microsoft.com/en-us/library/cc262432(office.12).aspx
http://social.technet.microsoft.com/Forums/en-US/sharepointadmin/thread/f53c0c3c-ec31-4a40-b822-055eac2d0e3e/