Showing posts with label Development. Show all posts
Showing posts with label Development. Show all posts

Sunday, November 04, 2012

How to re associate list workflows with lists after a migration in SharePoint 2010

Recently I had been exercised on migrating a sub site into a root web in a different site collection.One of the major issue, out of many, was none of the list work flows were working.

After further investigations, figured out that the issue was due to old list Id’s that were associated with the workflows from the source site which I exported.

Follow the steps below to re associate new list Id’s with the workflow using MS SharePoint Designer.

Step 1: Open the site in SPD

Step 2: Locate the workflow you want to re associate with new list Id's (See image below)

blogpost-workflow-1

Step3: Change the 4 list Id’s numbered in below image with the new Id’s

blogpost-workflow-2

  • DocLibID
    • The list Id for the workflow definitions lists (This is a hidden list and you can use SharePoint manager to get the list id)-Refer the image below

blogpost-workflow-3

  • ListID
    • The list Id that needs to associate with the workflow
  • TaskListID
    • "Workflow Tasks" list Id
  • HistoryListId
    • "Workflow History" list Id

Wednesday, May 18, 2011

Setting assembly version automatically when building in a Bamboo server

Scenario :
How to instruct your msbuild script to set the correct “AssemblyVersion” of your libraries using “AssemblyInfo.cs”  when building in a Bamboo server.In Puzzlepart it is vital to have the current build number and the current revision number in the assembly version of products.
Solution :
Assembly version syntax : <major version>.<minor version>.<build number>.<revision>
More info can be found here about the syntax. 
Step 1 : First you need to make sure the corresponding Build-Specific Variable are passed into the build script.
How ?
In Bamboo build configuration under the “Builder” tab you have “Options” where you can pass msbuild command line switches.
example : /p:BuildKey=${bamboo.buildKey} /p:BuildPlanName=${bamboo.buildPlanName} /p:BuildNumber=${bamboo.buildNumber} /p:Revision=${bamboo.custom.svn.revision.number}
image
Step 2 : Accessing those variables from the msbuild script
<PropertyGroup>
    <MajorVersion Condition="'$(MajorVersion)' == ''">1</MajorVersion>
    <MinorVersion Condition="'$(MinorVersion)' == ''">0</MinorVersion>
    <BuildNumber Condition="'$(BuildNumber)' == ''">0</BuildNumber>
    <Revision Condition="'$(Revision)' == ''">0</Revision>
    <BuildPlanName Condition="'$(BuildPlanName)' == ''">LocalBuild</BuildPlanName>
    <BuildKey Condition="'$(BuildKey)' == ''">NOKEY</BuildKey>


  </PropertyGroup>
Step 3 : Create the Assembly version using those properties
<PropertyGroup>
       <ComputedAssemblyName>$(MajorVersion).$(MinorVersion).$(BuildNumber).$(Revision)</ComputedAssemblyName>
</PropertyGroup>
Step 4 : Use the assembly version in “AssemblyInfo” task
<AssemblyInfo CodeLanguage="CS"
      OutputFile="$(ApplicationName)\Properties\AssemblyInfo.cs"
      AssemblyTitle="ApplicationName"
      AssemblyDescription="Description"
      AssemblyCompany=""
      AssemblyProduct="$(ApplicationName)"
      AssemblyCopyright="Copyright © "
      ComVisible="false"
      CLSCompliant="false"
      Guid="248D49F7-BC5D-4413-8E4A-98B4654B1594"
      AssemblyVersion="$(ComputedAssemblyName)" />

Wednesday, September 29, 2010

Integrating ReSharper into Visual Studio 2010

Scenario : I am running VS2008 and VS2010 in parallel in my development environment.And I had already installed ReSharper 5 before installing the VS 2010.Then I wanted to integrate the R# into VS2010.
Tried to find out how to do it by googling but to no avail.Only found out issues related to  integration issues with VS2010.
Then suddenly came to my mind that will the re installing R# help.As I re run the installer it prompted with the nice little option of changing the integration with the Visual Studio as in the bellow image.
resharper-1
When you click on the “Change” button you will get this
resharper-2
Now it’s a matter of ticking the check box for VS2010 integration and clicking the “Install” button.
Here we go, R# is at your finger tips in VS2010 now.

Sunday, September 05, 2010

SharePoint 2010 : First custom connector implementation for BCS

Today, I managed to read on BCS a bit and wanted to try out some custom connector implementation for the external systems.
Found out this code snippet from MSDN for a connector to the file system.
Managed to complete this exercise and created an external list with the External Content Type and I did see the files from the file system in the list.See bellow images.
Folder contents in file system :
source-files
External list in SP context :
list-ect
I am really impressed by this and it has already inspired me to go deep into this and hoping to create some more custom connectors for other external systems as well.
Found out lot of issues/problems while I am doing this and I just list down possible erroneous  scenarios.
  1. Business Data Connectivity Services issues
  2. Assembly deployment to the GAC
  3. Assembly information
  4. Configure Business Data Connectivity access rights
Keep those things in mind if you also get into trouble.  

Monday, July 12, 2010

Sharepoint foundation 2010 on windows 7 x64

Today,I installed Sharepoint Foundation 2010 on my laptop successfully according to this article.Downloaded the Sharepoint Foundation 2010 from here and started following the installation steps mentioned in this article.

The second step under “To set up a developer workstation” failed successfully because of this command “c:\SharePointFiles\SharePoint /extract:c:\SharePointFiles”
Here it referred to a file called “SharePoint” but the name of the downloaded application was “SharePointFoundation.exe”. So in order to pass this step I had to change the name from “SharePoint” to “SharePointFoundation” in the above command.

After that I continued with the installation steps and managed to launch the setup.exe after completing the installation of prerequisites mentioned.
In the 3rd step under the  “Step 3: Install SharePoint 2010” I select the “Server Farm” option and in the next step I selected the standalone option.I had no clue what so ever why I selected that option, but it happened for some reason and it worked.

Then I had to wait for a quite a longer time to complete the installation and prompted to run the sharepoint configuration wizard.
And finally after the configuration wizard completed, it prompted the newly created sharepoint team site.(See image at top)

Now sharepoint foundation 2010 at my finger tips so that I can start playing with it.

Saturday, November 14, 2009

Thursday, October 29, 2009

Embedding YouTube videos in your blog

Very simple to do this.Just open the video you want to embed in YouTube and then right click on the video and click on the “Copy embed html” and then copy that copied html code into your blog entry markup.

Here is the embedded video into this blog entry :



References : http://www.youtube.com/youtubeonyoursite

Tuesday, September 15, 2009

Internal names should be used in SPQuery

Today I found out an interesting issue when I accidentally changed a field name used in a query used in SPQuery.

I wanted to change the display names of my fields and after doing that I renamed all the usages of that field name in my web part code.

After deploying the solution I got the error message "One or more field types are not installed properly. Go to the list settings page to delete these fields"

I had no clue what so ever when you read that error message.This is not the only error message that share point generates which we cannot figure out by looking at this.

I spent considerable amount of time debugging the solution until I decided to Google the error message.

Then found that in one of the msdn forums that the internal names of the fields should be used in the CAML queries.

reference : http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/a2c6bed0-eee1-4f9b-b468-fc57c2e45c16

And that was indeed the trick.

Wednesday, September 02, 2009

How to create active directory users programmatically

Recently one of my colleagues wanted a piece of code which can be created 500 users in Active Directory for some testing purposes.Knowing that this won’t be a big challenge I said I will give it a try.

Frankly speaking, initially I thought this will be a easy walk in the park.Creating the user in AD part was a piece of cake but the created user was not enabled by default.

I had to figure out how to enable a user account programmatically.That was the only tricky part.

Check the user enabling code segment in the code.(Setting the "userAccountControl" property of the user)

Here is the code

string ldapPath = "LDAP://" + server + "/cn=Users,dc=ec,dc=test";

DirectoryEntry entry = new DirectoryEntry(ldapPath, user, pwd);

for (int i = 0; i < userCount; i++)
{
string tempName = userPrifix + i;
DirectoryEntry newUser = entry.Children.Add("CN=" + tempName, "user");
newUser.Properties["givenName"].Add(tempName);
newUser.Properties["userPrincipalName"].Add(tempName + "@ec.test");
newUser.Properties["sAMAccountName"].Add(tempName);
newUser.Password = userPwd;

newUser.CommitChanges();

// Enabling the above created account
int flags = (int)newUser.Properties["userAccountControl"].Value;
newUser.Properties["userAccountControl"].Value = flags & ~0x2;

newUser.CommitChanges();

newUser.Close();
entry.Close();
}
References :

http://www.codeproject.com/KB/system/everythingInAD.aspx

http://www.computerperformance.co.uk/Logon/LDAP_attributes_active_directory.htm

Tuesday, August 18, 2009

How to avoid recursive calls in list item event receivers in SharePoint

I wanted to insert a value into a column in a list when adding and updating items in the same list.

First I registered the item event receiver into the list.

SPList list = web.Lists[listName];
list.EventReceivers.Add(eventType, assemblyName, className);

Then in the actual event receiver class I override the “ItemAdded” and “ItemUpdated” methods.



public override void ItemAdded(SPItemEventProperties properties)
{
SPListItem item = properties.ListItem;
string itemStatusValue = string.Format("Item added @ {0} by {1}", DateTime.Now.ToLocalTime(),
properties.UserLoginName);
item["columnName"] = itemStatusValue;

item.Update();
}

public override void ItemUpdated(SPItemEventProperties properties)
{
SPListItem item = properties.ListItem;
string itemStatusValue = string.Format("Item updated @ {0} by {1}", DateTime.Now.ToLocalTime(),
properties.UserLoginName);
item["columnName"] = itemStatusValue;

item.Update();
}

But when I debug this in VS2008 I noticed that, as the item get updated or added it always calling to the “ItemUpdated” method.Of course that is understandable since I am updating a column in the same list.

But I didn’t want that to happen.Then I found out that you can enable/disable event firing.

So the solution for that is ,

DisableEventFiring();
item.Update();
EnableEventFiring();

It is pretty straight forward once you get to know it.

More references on this : Visit BinaryJam

Friday, August 14, 2009

How to avoid inline codes in user controls in SharePoint web parts

When I was at the beginning of developing web parts for SharePoint , I wanted to find a way of reducing the time consume to develop web parts using Web User Controls (*.ascx) as web parts.Otherwise you will have to write all the mark ups in the CreateChildControls method.

Check here how to use web application projects to develop web parts.

So I was very fond of that method till I figured out, this is not going to inline with the SharePoint deployment techniques.Especially if you are using wsp solution packages and 12 hive structure in Visual Studio with WSPBuilder.

Recently in a project that I was working with, I used a slightly different approach to which I was used to.That is not using web application projects but I used the user control(*.ascx file) with inline codes for the web part in the templatecontrol folder.

There are pros and cons having inline codes.

The code is visible to a person who has access to the server directly.

If it is a complex web part your lines of code will be very high and which will lead to readability and maintainability issues.

Today I managed to figure out how to move inline code into your main assembly of your SharePoint solution and I thought of sharing that with you.

SampleWebPartControl.ascx (user control)

What is important here is that the entry in the RED box in above image.That is the way you specify where the code behind can be found for this user control.

SampleWebPartCOntrol.cs(code behind)

The initialization of user controls you are using is paramount(check the RED box in this image).I had all sorts of problems till I sorted that out.

Solution Structure

Check where the items in the RED box in this image.

Friday, August 07, 2009

List content type troubleshoot

Recently I had a problem with the default content types that are bind with a custom list.

I created an Announcement list and I have bind my own content type into it.Then I wanted to hide the default content type which is the “Announcement”.Initially I used the name to get the content type from the list but later I had to re factor it simply because, if we are to support multilingual we should not use names but id’s.

Then I thought this should be a piece of cake and I re factored it like bellow.

SPList list = web.Lists[listName];
SPContentType item = list.ContentTypes[SPBuiltInContentTypeId.Announcement];
item.Hidden = true;
item.Update();
list.Update();

To my amazement , as I activated the updated feature I got the error “Object reference not set to an instance of an object”.

And then I open this list from the SharePoint Manager and checked the ID of the content type “Announcement” and it is totally different one to the default content type id which is the “0x0104”.

Then I got some expert help on this and got to know that this is because what ever the bind content types in lists are a copy of the site content type.Thank you Bjorn for letting me know about it.

So here is the new code of doing it.

SPContentType item = list.ContentTypes[list.ContentTypes.BestMatch(contentTypeId)];

It was that simple once you got to know it.

So what you need to understand here is that adding a content type to a list means that you actually adding a copy of the content type.

Saturday, June 20, 2009

SharePoint tools for developers

There are very important tools that you can use while you are working with SharePoint development work.

I thought of putting down very important tools that you can use when comes to developing SharePoint projects.Those tools are really handy on reducing your development time as well as troubleshooting time.

WSP Builder – This is a VS extension which is fully cable of deploying sharepoint solutions.This is a dream tool you can think of the problem you are facing when comes to deploying SharePoint solutions.

Hats off to Carsten Keutmann

SharePoint Manger – This is a very useful tool to explore the every item in your SharePoint installation.

BareTail – This is also very important tool that can be used to view the SharePoint log files which lies in the 12 Hive.And you can use this tool to monitor any log file for that matter

Tuesday, June 16, 2009

Document Template Management in SharePoint

Very good article on SharePoint document template management.

Read it here.

Saturday, May 23, 2009

Localization of web parts in SharePoint

My colleague Sanjaya has posted a fantastic article on localizing SharePoint web sites and web parts.

One of the major problem when comes to localizing web parts is that you have to have all translations relates to the locale you are using, if you are to build the embedded resources.

So I would prefer let the customer do the translations rather than we do it.In that case if you can send the set of resources files ( *.resx ) to the customer he can easily open those files and he can do the translation as he needs.

What my colleague mentioned in his article is totally alright but it is not entirely to my likings when comes to localizing web parts because of the above mentioned reason.

So I just used the resources files (*.resx) but not deployed them as embedded resources.

How to do it ?

  • Add the relevant resource files in to your web part.
  • Use the following fragment of code to access the resource strings from the resource files as required in your controls.
  • HttpContext.GetGlobalResourceObject("<resource file name>", "<resource key>").toString()
  • Make sure to have the resource files in the “App_GlobalResources” directory of the corresponding web application project.

More can be read from the following references :

http://tomblog.insomniacminds.com/2008/02/25/sharepoint-internals-resources/

http://www.mikhaildikov.com/2007/03/sharepoint-resources-types-use-and_2163.html

Friday, April 17, 2009

8 Characteristics of successful UIs

Read a very very good article on things to consider when designing user interfaces.

8 characteristics are :

1. Clear
2. Concise
3. Familiar
4. Responsive
5. Consistent
6. Attractive
7. Efficient
8. Forgiving

Read the full article here.

Thank you very much Uchitha for sharing this wonderful article with us.