Saturday, July 16, 2011

Activate only selected features while deploying a solution package in Visual Studio 2010

In Visual Studio 2010 SharePoint Developer Tools is what we use to develop quick solutions to SharePoint. With these tools we can quickly deploy into SharePoint environment as well. But, the only issue we see here is, if we are trying to deploy a package which contains a set of 5 features then all of them will be activated by default. But, this might not be a valid behavior for us. We need to activate only 3 features while deploying the package and the other 2 features need to be installed into SharePoint but should not be activated. So, this is not available by default in the SharePoint Development Tools in Visual Studio 2010.

Recently when I was browsing in internet for this, how to deploy only selected features into SharePoint, but not all and found a great Visual Studio 2010 Extension. Which is a great tool to use and works perfect.

Download the extension here.

Once you get his extension, directly run it by double clicking on it. Before you see the changes, close any existing Visual Studio instances and reopen them. The extension will be added to Visual Studio 2010 and ready to use. But, to use it in your SharePoint project, you need to do one more exercise.

Permissions for document 'Move' operation in SharePoint

This might not be a super thing to blog but very important point to note. Through code I have tried to move a document from one document to another document by using file.MoveTo() operation. It was working very fine when I tested as I am administrator in the dev environment. But, when I have given to QA for testing it was failing. I have tried so many combinations of giving different access to them and nothing worked. When I have given them either Owners or site collection administrator access it started working. So, I was not understanding of what was the permission level do they need?
After tried different combinations of permission levels to them one matched and worked perfect. That was Contribute and Approve permission levels. So, for the logged in users who don't have both of these permission levels the code is failing for them and the  result file was not moving successful. [Another note is, I am using publishing site with auto approval of document in document library.]

Code used:
SPFile file = currentItem.File;
file.MoveTo(filePath, true);
For a document move operation the logged in user should need both Contributor and Approve permission levels for publishing web sites in SharePoint.

I am thinking it is correct according to my analysis and research. Please let me know if something is wrong in this post or any better solutions.

Move and Copy operations in SharePoint Lists

Do not know how many of you aware of these important points.

  1. When you move a document/list item from one document library/list to another then the versioning will also be retained in that destination library/list.
  2. When you copy a document/list item from one document library/list to another then the versioning will not be copied to the destination library/list.
  3. When you move a document/list item from one document library/list to another then the metadata will not be copied. To do that you should have same columns in both libraries/lists and they should use same content type [Means they should have same schema].

How to hide a specific div in SharePoint 2010 dialog

The class in styles "s4-notdlg"[means don't show in dialog not+dlg] is what we have to use to not show a specific division on SharePoint 2010 dialog.

For example, there is a banner in the header position of the master page and you do not want to show the banner in the dialog then the only simple option for you is using a simple css class to your banner div. If you add this class to your banner then when no dialog on the page no change to your implementation but when you are on dialog then the division with the class "s4-notdlg" will be forcibly applied to "display:none".

So, the moral of the story it is a good tactic that Microsoft SharePoint team developed to solve some major issues in design on dialogs.

Saturday, July 2, 2011

Upgrade SharePoint 2007 Visual Studio projects to 2010

This will be very helpful for the scenarios where we have custom solutions developed in Visual Studio 2008 for SharePoint 2007 environment and upgraded 2007 site to SharePoint 2010 and now in SharePoint 2010 we like to do some changes to that custom solution files. Simply, we have a SharePoint 2007 site upgraded to SharePoint 2010 and then it has some custom solutions developed like web parts, solution packages, features etc. Now, we are in SharePoint 2010 environment and like to extend the custom web parts, features from the earlier version of SharePoint. So, we need some sort of support to migrate our SharePoint Visual Studio projects from Visual Studio 2008 to Visual Studio 2010 to deploy to SharePoint 2010. I believe you all are clear till this point.

Get the tool here. http://archive.msdn.microsoft.com/VSeWSSImport/Release/ProjectReleases.aspx?ReleaseId=4183

It is simple project and when you build it, you will get executable and installs template to Visual Studio. But, the only preliminary requirement here is, you have to install Visual Studio 2010 SDK to open project.

Once everything is ready, you will see a new template named "Import VSeVSS project" under new project category. Here you go.....

SharePoint workflow staus codes

This is very important for SharePoint devs. Even I have used them many times, but I forget the status codes almost every time. So, might be happening to everyone too and planned to blog in my blog.

The enum SPWorkflowStatus in the namespace "Microsoft.SharePoint.Workflow" in the library "Microsoft.SharePoint" is what we have to use for these status codes.

0
NotStarted
Not Started
1
FailedOnStart
Failed On Start
2
InProgress
In Progress
3
ErrorOccurred
Error Occurred
4
StoppedByUser
Cancelled
5
Completed
Completed
6
FailedOnStartRetrying
Failed on Start (retrying)
7
ErrorOccurredRetrying
Error Occurred (retrying)
8
ViewQueryOverflow
--
9-14
Unknown
Unknown
15
Cancelled
Cancelled
16
Approved
Approved
17
Rejected
Rejected

Hope this is enough for us to get what we needed.  :)

Error occurred in deployment step ‘Recycle IIS Application Pool’: The communication object, System.ServiceModel.InstanceContext, cannot be used for communication because it has been Aborted

When we are developing custom code through Visual Studio 2010 for SharePoint 2010 sites and when we try to deploy the solution then we might see the below error.

"Error occurred in deployment step ‘Recycle IIS Application Pool’: The communication object, System.ServiceModel.InstanceContext, cannot be used for communication because it has been Aborted."

When I see this very first time and did not get any clue of what it is looking for and why it is not able to communicate to SharePoint sites. After doing some trail and error methods and checking Event Viewer, Logs etc... failed in all the ways in deploying the custom piece to SharePoint. Finally, a simple solution worked but didn't find any reason what is the main issue!

Solution:
  1. Sometimes when I do rebuild the project and deploy directly without doing "Package" from Visual Studio it is successful. 
  2. If it is not successful then the only way I see is RESTART your visual studio and deploy.
  3. (From below comments: ) Restarting "Windows Management Instrument" service will work. (I haven't tested).
Frustrated hours come to an end... There is some way always to make our life go smooth! Happy programming.