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.

Friday, April 29, 2011

Managing user alerts

Managing user alerts is very important aspects of administrator. Many times we come across to a requirement asking Is there any way where I can see list of all users who have subscribe for an alert. Answer is yes, there is.

However, this can be view only by site administrator with full control and of course site collection administrator.

To view all user alerts, go to site settings - > User alerts under site administration. When you click on it and you come on the page where you can see list of all users who have subscribed for alerts.



Select specific users and then click on update, this will show you all alerts been subscribed by that user and from there you can remove the alerts if you want.

This might be useful because of one drawback that alert has. If you subscribe alert more than one time on same list for the same alert settings; i.e. let’s say I have subscribed for getting an alert if someone changes an item created by me. And I did the same procedure to subscribe for the same alert two times more, then when someone changes the item created by me, I will get three times alert not one time which is really a big problem for high level position people in the company and not acceptable at all.

Hence administrator will see alerts been subscribe three times, so admin can come here and remove duplicate alerts.



Individual user can manage alerts from their alerts section of the site and do the same thing, it’s just that administrator can see all user’s alert. Although this is tedious job to do; but it solves the purpose.

Thursday, April 28, 2011

Understanding document set - Part 1

One of the cool new features available in SharePoint 2010 is document set. We can consider document set as a folder in which there can be one or more document resided. Consider it a folder with advance functionalities.

Document set is a collection of documents. Documents can be word, excel, PowerPoint or simply any office document.

Document set is a content type, so ultimately we are defining what all content types are allowed in a document set and then we can create a document set based on those content types.

Example, let’s say you have one project going on and you have a defined process to prepare some documents for the project. First requirement document is being prepared, then some technical draft is prepared, at the same time some budgeting proposals are prepared and then sales plan document is prepared.

There can be a scenario where all your documents share common metadata properties, and then you might want to club those documents into one for easy search and version control.

If you have some process or fixed set of documents for some reason then you can combine all those documents into one single document set.

Document set has a default web part page that comes when you open the document set which gives us the information on properties of the document set and shows all documents that are part of the document set.

Some of the advantages of document set are:


1) Common metadata for all documents in document set
2) Automatic creation of documents when setting up the document set
3) Web part page that shows the properties of document set and which is customizable. We can have a dedicated customized web part page per document set if we want.
4) Document set has their own ribbons to carry out actions related to document set.
5) One of the main advantages is workflow directly on document set rather than running individual workflow for each document in document set.
6) Versioning on document set rather than versioning on each document in document set.
7) Permissions can be set on document set rather than each individual document.
8) Download all documents as zip package rather than downloading individual document.

Explore more in to see document set in action in part 2

Wednesday, April 27, 2011

Creating external lists in SharePoint 2010 – Part 2

Here we are with part 2. If you have not gone through part 1, then I recommend you reading part 1 first before proceeding. Once you are done with reading part 1, then come back and read this part 2 to understand it bit more.

Now remove the Employees list from the SharePoint site we created earlier. Now open SharePoint Designer 2010 and open the Employees external content types.

Click on create list and form.



Then give name of the list and description. System instance will be Employees because as of now we only have one external content type in my system.



Click on Ok, it will display creating Employees list



Go back to the SharePoint site and check that list has been created. Also make a note that it shows that list is external.



If you create InfoPath form, then it appears like this




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