Tuesday, May 17, 2011

Delete button in list view

Hi, we all know that list view is the best way to show the data to use without wasting of time.

It gives all the basic required functionality but as always client ask few simple things which SharePoint is not providing by default.

And for that silly thing we have to create custom webpart or custom listview

We already shown you few ways to show how you can change your listview HTML by JQuery and JavaScript like
http://www.sharepointkings.com/2010/04/sharepoint-custom-so-called-kpi.html
http://www.sharepointkings.com/2008/12/highlight-sharepoint-list-rows.html
http://www.sharepointkings.com/2009/04/sharepoint-calculated-column-and-jquery.html
All jquery stuff http://www.sharepointkings.com/search/label/JQuery

Recently we got requirement that client needs delete button link in SharePoint list view
Now edit button is available but delete button is not available in default view.

So finally we are went the same way as we always used: change the Listview HTML in JavaScript

We created a text field “Delete” and put some below text inside that field
<div><a href='#' onclick='javascript:DeleteItem(2);'><img alt='delete' src='/_layouts/images/delitem.gif' style='border:0px;' /></a></div>
where 2 will be listitem ID

Note: calculated column is not supporting ID. So we can use event handler or SPDesigner workflow to fill this field.

Now what we had done is on DeleteItem function we called web service from JavaScript using SPServices jQuery and delete the item and then just reload the thepage.

That’s it
Here is the function which called on page load to change text field to div field.

we have to put this JavaScript on the same page of list view.


$(document).ready(function(){
$(".ms-vb2:contains('<div')").each(function(){
var tempDIV = document.createElement ("div");
tempDIV.style.cursor = "pointer";
tempDIV.innerHTML = $(this).text();
$(this).text("");
$(this).append(tempDIV);

});
});

function DeleteItem(cID)
{try{
var cnf = confirm("Are you sure you want to send the item(s) to the site Recycle Bin?");
//this is default message that sharepoint gives.
if(cnf)
{
$().SPServices({
operation: 'UpdateListItems',
listName: ‘your list name’,
batchCmd: 'Delete',
ID: cID,
completefunc: function (xData, Status) {
location.reload(true)
}
});
}


}catch(ex){alert(ex);} }</script>


Hope fully you will get the idea how its working.

Delete Drop off library Part – 2

Here we are with part 2. If you have not gone through part 1, I would recommend you reading part 1 and then come back here for further reading.

As we know that by default there is no option to delete a drop off library and we saw in part 1 one way to enable the delete this library settings under permissions and management.

With the help of PowerShell script we can achieve this as well.

All you need to do is go to administrative tool -> PowerShell modules and type in following commands.


$objWeb = Get-SPWeb –Identit http://ServerName
$objDocLib = $objWeb.GetList("http://ServerName/sites/sitename/DropOffLibrary");
$objDocLib.AllowDeletion = "True";
$objDocLib.Update();


And you are good to go. You will be able to see delete this library option under permissions and management.

Read Part3 for further reading

Monday, May 16, 2011

Delete Drop off library Part – 1

Drop off library which is a part of content organizer in SharePoint 2010 is one of the cool new features been added to SharePoint 2010.

If you want to know more about drop off library, you can read it here.

Now the interesting this is, if you go to drop off library settings, you will not see the delete option by default.

This is the default settings, may be because drop off library is an important feature and there can be multiple rules might have been set on it.

However, if we want to remove this library then there are three ways. I am going to convert them in one by one part. In this part, we are going to see how we can enable deleting library from server object model.

First let’s have a look at the screen shot of drop off library settings.



Now write below code wherever appropriate.



And here is the result



Read more in Part 2.

Thursday, May 12, 2011

Word automation services – Part 1

Common requirement is to convert doc to PDF and for that we often go for the third party software, do the conversion online, in development go for the third party DLL and then call method to do this job.

We now also have an option to convert word document in PDF in office 2010.

Well, now with SharePoint designer 2010 or word automation services, it is possible to convert word document to the PDF file and that too without any watermark.

Word automation service is only available in SharePoint server 2010 not in foundation server.

Word automation service can convert document to one format to another format. You can also do this programmatically as well.


It can read following file formats.
• Word 97-2003 Document (DOC) and Word 97-2003 Template (DOT)
• Rich Text Format (RTF)
• Single File Web Page (MHTML)
• HTML
• Word 2003 XML
• Word 2007/2010 XML

And it can write following file formats.

• PDF
• XPS
• Office Open XML (DOCX, DOCM)
• Word 97-2003 Document (DOC)
• Rich Text Format (RTF)
• Single File Web Page (MHTML)
• Word 2007/2010 XML

So definitely this is a great move from MS and it was highly needed.

Before starting on this, we need to make sure that word automation service is started on the server.

Go to your central administration – Application management – Services on server and see that it is started, if not, then start it.



In this post, I am going to show you how to convert a document to different formats from word and from other formats.

This time we will start with the code. Yes, directly we jump in to the code because it is really easy to convert a document from code for the developers. Just to show you how it works, I am using documents in the same library and outputting the resulting converted documents to the same library.

Output library can also be different from the site. I yet have to check if it works for the site collection or not. But for the site, it definitely works.

You need to include one DLL reference in your project and that is Microsoft.Office.Word.Server.Conversions.ConversionJob.



Once you execute this code, you might have to wait for couple of minutes or more. It depends on the type of file you are converting. Check out different options in conversions.SaveFormat. There are different formats available.

Output from the same above code tried with different formats is shown below.



First is .docx, converted to .doc, .pdf and .xps.

Now one more thing to add here. When you have job object in your hand then you can query its conversion status. As I said earlier, for some file format conversions it might take few minutes.

ConversionJobStatus status = new ConversionJobStatus("Word Automation Services", job.jobId, null);
if (status.Count == status.Succeeded)
{
// converted

}
else if (status.Count == status.Failed)
{
//Not converted. It has failed

}


Read Part 2 for further reading.

Wednesday, May 11, 2011

Understanding document set - Part 2

Let’s continue exploring document set. If you have not gone through part 1, I would recommend you go through it before proceeding. Part 1 will give you understanding on what the document set is all about and what are the advantages in that.

Go to site collection features and activate the document set feature.



Once you activate the document set feature, you would be able to apply it on the content type of document library.

Go to the document library where you want this document set. Go to library settings -> Advanced settings->



Go to list settings page and click on add from existing site content types.

Select document set content type and select document set.



Once you have added document set, and then go to document library and then click on New to create document set. Give name and the description of the document set.



This will create a document set in the library.



Click on the Project Document will take you to the detailed page of the document set.



You can also see that document set specific actions comes alive as a context sensitive ribbon controls.



Document set it has its own properties. You can add columns to it same way we add columns to the normal list or libraries. These will serve as a Meta data for the document set.



Let’s add couple of documents in it, couple of excels files and a presentation in it.



This is it for this part. Keep reading Document Set Part-3 for further reading..

Monday, May 9, 2011

Common list operations in SharePoint 2010

In this post, we are going to see how to implement some of the cool new features in SharePoint 2010 for the list through programming.

1) How to add validation for the field in the list



2) How to add list validation



3) How to add referential integrity (cascading delete or cascading restrict) to the relationhip list

Saturday, May 7, 2011

Result is out

Result of last polling is out and it looks like people has given thumbs up to Google Android followed by Microsoft Windows Phone 7 and surprisingly followed by iOs.

Friday, May 6, 2011

Enforce unique constraint from code

We have seen in previous posts that it is very easy to set field with the unique constrain from list settings. We are going to see the same using code that how to do that

Below is a sample code to achieve that. We must remember that before a field can be set to unique constraint, we have to index that field and hence we have also set that as well.

Wednesday, May 4, 2011

Opening any SharePoint page as model dialog SP2010

Hi Guys,

As we all know that sharepoint 2010 is opening a lot of forms in its newly featured model dialog.

Few of this pages are list forms like NewForm.aspx, EditForm.aspx, DispForm.aspx, pages while creating new object like list,site…etc.

While customize your sharepoint site, if by any chance you required any of your page to show in model dialog then below is the code for the same.
function OpenDialog(strPageURL,strDialogTitle) {

//Creating New Object for SharePointDialog
var newDialogOptions = SP.UI.$create_DialogOptions();

//set URL for Dialog to open
newDialogOptions.url = strPageURL;

//you can set your custom size by setting height and width
autoSize: true,

//set title to show on head of dialog
newDialogOptions.title = strDialogTitle;

// This line required only if you want to call a function when we close dialog -- here we refresh the page
newDialogOptions.dialogReturnValueCallback = Function.createDelegate(null,CallbackFunc);

//open the dialog
SP.UI.ModalDialog.showModalDialog(newDialogOptions);

return false;
}

function CallbackFunc(result, target) {
//Refresh the current page
location.reload(true);
//some suggest to use below line but sometime this was not working
//so we are working on that
//SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);

}



The good thing for us is you can open any page with this dialog.

That page might have you custom webpart as well or anything will work.

Even JavaScript, query string, postback etc… available on that page because that page work similar as normal page it will also remove limitation of traditional model dialog.

If we want to refresh parent page after closing popup then also we can do that (as shown in code)

One more thing if you want to open another model dialog from already open model dialog then also this one is working

Thanks Antonio Lanaro for his wonderful post on this one.

Enjoy the popup.

Tuesday, May 3, 2011

Send email to attendees from designer workflow

You may come across to a common scenario where in you may want to send an email to attendees in the calendar list. Or let’s say you have a manager name as a field and then you want a leave approval from them, so you select manager name in the field and submit the button, then you want mail to go to that manager or the attendee.

Many of us have doubt that if this is possible out of the box or not, but yes this is possible through SharePoint Designer. We are talking about the sending an email to one of the field data from the list item not to static email address.

Let’s say I have a calendar list and I have a manager name field in it. So open SharePoint designer 2007 or 2010, navigate to your site. Create a new workflow, based on your requirement, select list and then on new item created.

In condition to make it always true, compare ID field with the ID field and then in actions, select send an email.





Select Workflow lookup and then from current item, select field. In my case, its manager name.



So now onwards, if any item is created in the list, then mail will be triggered to the name mentioned in the manager name field.



Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com