Thursday, May 23, 2013

Sharepoint 2010 Administration - Unable to retract and remove the WSP solution. Its Weird !!!

Today i encountered an issue where in i am not able able to retract and remove the WSP solution.

Below are the steps which helped me in doing the above task.

ISSUE FACED :)
When we try to retract the solution the status will show retracting(the timer job will be created for that) but when we press F5 the status will change it to deployed. its very strange tat i am unable to retract and remove the solution.

The below image shows its retracting when i click on retract.


The below image shows deployed once the it completed the job (STRANGE) :)


Now how to retract and remove the solution

SOLUTION

Once i retracted the solution i tried executing the below command  which didnt help and i got the error message saying "The administration service is running so all administration jobs will be run in the timer service"
stsadm.exe -o execadmsvcjobs

Below is the Error Image

After that i went to services.msc and stopped the "SharePoint 2010 Administration Services"

Now again i tried retracting the WSP and got the below error message


 Which means the timer job for retracting operation has been created. but it waill fail because the adminstrative service for this server is not enabled :) "EXPECTED"

also they provided the command in the error msg to for exectuting the timer jobs. Tried running the command it worked properly and then i started SharePoint 2010 Administration service again.

Below is the commands which i used.


Well  this is not the permanent fix. But its retracted and removed the solution :)

Hope this will be useful :)

Monday, February 18, 2013

SharePoint 2010 Records Management LockItem and UnlockItem

Well today i was doing some poc on Inplaee record management in SharePoint 2010 and faced some interesting points.


The reason i started doing poc is to lock a SharePoint list item and unlock a item.
becuase once it locked other user cannot edit the item. There are so many other methods also there to accomplish this. But i found two methods in SharePoint 2010 API which is there in below namespace

using
Microsoft.Office.RecordsManagement.RecordsRepository

Also, we need to add "Microsoft.Office.Policy" dll to get the above namespace.

The two methods are

Records.LockItemRecords.UnlockItem

Now there are other methods are there like Records.DeclareItemAsRecord and
Records
.UndeclareItemAsRecord to acheive the same. now is question like why i didnt use
the reason i didnt use is once you declareitemasrecord i missed the delete this list option in list settings. then i thought we can use the alternative.

Okay again in this method also i faced problem like it requires
_vti_ItemHoldRecordStatus column to the lock and unlock methods. (Note this is hidden column)

Then i started creating contenttype and given the below reference
<?xml version="1.0" encoding="utf-8"?><
Elements xmlns="http://schemas.microsoft.com/sharepoint/"><!--
Parent ContentType: Item (0x01) --><
ContentType ID="0x0100d6c72b455db04e61824b10c707ca4f9c"Name="LockItem - TestContentTypeSample"Group="Custom Content Types"Description="My Content Type"Inherits="TRUE"Version="0"><
FieldRefs><
FieldRef ID="{F9A44731-84EB-43a4-9973-CD2953AD8646}" Name="_vti_ItemDeclaredRecord" DisplayName="Declared Record" Required="FALSE"/><
FieldRef ID="{3AFCC5C7-C6EF-44f8-9479-3561D72F9E8E}" Name="_vti_ItemHoldRecordStatus" DisplayName="Hold and Record Status" Required="FALSE"/><
FieldRef ID="{740931E6-D79E-44a6-A752-A06EB23C11B0}" Name="_vti_ItemIsLocked" DisplayName="Is Locked For Edit" Required="FALSE"/></
FieldRefs></
ContentType></
Elements>

Next i created list definition with above content type refer below snippet

<List xmlns:ows="Microsoft SharePoint" Title="ListSample" FolderCreation="FALSE" Direction="$Resources:Direction;" Url="Lists/LockItem-ListSample" BaseType="0" xmlns="http://schemas.microsoft.com/sharepoint/"><
MetaData><
ContentTypes><
ContentType ID="0x0100d6c72b455db04e61824b10c707ca4f9c" Name="LockItem - TestContentTypeSample" Group="Custom Content Types" Description="My Content Type" Inherits="TRUE" Version="0"><
FieldRefs><
FieldRef ID="{F9A44731-84EB-43a4-9973-CD2953AD8646}" Name="_vti_ItemDeclaredRecord" DisplayName="Declared Record" Required="FALSE" /><
FieldRef ID="{3AFCC5C7-C6EF-44f8-9479-3561D72F9E8E}" Name="_vti_ItemHoldRecordStatus" DisplayName="Hold and Record Status" Required="FALSE" /><
FieldRef ID="{740931E6-D79E-44a6-A752-A06EB23C11B0}" Name="_vti_ItemIsLocked" DisplayName="Is Locked For Edit" Required="FALSE" /></
FieldRefs></
ContentType></
ContentTypes><
Fields><
Field ID="{F9A44731-84EB-43a4-9973-CD2953AD8646}" Name="_vti_ItemDeclaredRecord" StaticName="_vti_ItemDeclaredRecord" DisplayName="$Resources:dlccore,RecordResourcesItemDeclaredRecord_DisplayName;" SourceID="http://schemas.microsoft.com/sharepoint/v3" Group="$Resources:dlccore,RecordResourcesColumnGroup;" Type="DateTime" Indexed="FALSE" Hidden="FALSE" CanToggleHidden="TRUE" ShowInNewForm="FALSE" ShowInEditForm="FALSE" ShowInFileDlg="FALSE" ShowInDisplayForm="TRUE" Required="FALSE" Sealed="TRUE" ReadOnly="TRUE" /><
Field ID="{740931E6-D79E-44a6-A752-A06EB23C11B0}" Name="_vti_ItemIsLocked" StaticName="_vti_ItemIsLocked" DisplayName="$Resources:dlccore,RecordResourcesItemIsLocked_DisplayName;" SourceID="http://schemas.microsoft.com/sharepoint/v3" Group="$Resources:dlccore,RecordResourcesColumnGroup;" Type="Boolean" Indexed="FALSE" Hidden="TRUE" CanToggleHidden="TRUE" ShowInNewForm="FALSE" ShowInEditForm="FALSE" ShowInFileDlg="FALSE" ShowInDisplayForm="TRUE" Required="FALSE" Sealed="TRUE" ReadOnly="TRUE" /><
Field ID="{3AFCC5C7-C6EF-44f8-9479-3561D72F9E8E}" Name="_vti_ItemHoldRecordStatus" StaticName="_vti_ItemHoldRecordStatus" DisplayName="Hold and Record Status" SourceID="http://schemas.microsoft.com/sharepoint/v3" Group="Document and Record Management Columns" Type="Integer" Min="0" Max="32" Decimals="0" Indexed="FALSE" Hidden="TRUE" CanToggleHidden="FALSE" ShowInNewForm="FALSE" ShowInEditForm="FALSE" ShowInFileDlg="FALSE" ShowInDisplayForm="FALSE" Required="FALSE" Sealed="TRUE" ReadOnly="TRUE"/></
Fields><
Views><
View BaseViewID="0" Type="HTML" MobileView="TRUE" TabularView="FALSE"><
Toolbar Type="Standard" />
Now i got the list instance. next make sure you have selected the below option in list settings->record declartaion settings->


Finally below is the code snippet to lock or unlock the item


  protected
void btnLock_Click(object sender, EventArgs e){

SPWeb web = SPContext.Current.Web;
SPList list = web.Lists.TryGetList("ListSample");
SPListItem item = list.GetItemById(Convert.ToInt32(txtID.Text));
if (item != null){

Records.LockItem(item, "itemToLock");}
}



protected void btnUnLock_Click(object sender, EventArgs e){

SPWeb web = SPContext.Current.Web;
SPList list = web.Lists.TryGetList("ListSample");
SPListItem item = list.GetItemById(Convert.ToInt32(txtID.Text));
if (item != null){

if (Records.IsLocked(item)){

Records.UnlockItem(item, "itemToLock");}
}
}

if you locked with "itemToLock" you must unlock with the same name otherwise you will receive an error saying object refernce not set to an instance of an object :)