Friday, December 7, 2012

Hide List Menu in SharePoint 2007

This post is for my future reference. I was working in InfoPath 2007 form (with Document Library) and there was a requirement to stop user creating new forms for few days. So my ultimate goal was to hide NEW menu. With my research, I got to know that via SharePoint Designer and JavaScript, we can hide this menu. 


  1. You can open your site in SharePoint designer.
  2. Open AllItem.aspx page (if this is your default view) of your InfoPath Form form library.
  3. Switch to Design mode and Right click on list.
  4. Select "Convert XSLT data view".
  5. Now, you can make changes on controls available on *.aspx page.
  6. Select NEW menu and then move to Split view and you will see  the XSLT code"

<SharePoint:NewMenu runat="server"></SharePoint:NewMenu>" 
//Set the "td" visibility as "hidden":
<td class="ms-toolbar" nowrap="" style="visibility: hidden">
<SharePoint:NewMenu runat="server" ></SharePoint:NewMenu

</td>
<td class="ms-toolbar" style="visibility: hidden">|</td>

7. Save your page on Designer.
8. Refresh your page in Browser to see the change.
9. There is a limitation with this approach. Now, you cannot modify default view of this List on SharePoint.You can revert to list view web part by right clicking on dataview web part and selecting "Revert to SharePoint list view" and try other suggested options.
OR
To add new fields or update fields sequential orders, open the page in SharePoint designer and right click on dataview web part and select "Show Common Control Tasks". Now, select "Edit Columns..." option to add new fields.
Follow link over here, if you want to use JavaScript to hide menus.

Monday, November 26, 2012

Executing code with Full Control in SharePoint 2007

This post I thought to write for my future reference and for other people who are facing issue while executing code and getting issue with access.

My requirement was to implement Cascading drop down functionality in Datasheet mode. So, I thought to write Event Receiver feature in VS2008 for SharePoint 2007. Attach feature with List.

Note: Cascading drop down and attaching Event Receiver feature to list is not scope of this article.

I implemented the code with below methods:

public override void ItemAdded(SPItemEventProperties properties)
{}

public override void ItemUpdated(SPItemEventProperties properties)
{}

Hence, I tried running code with my account (Admin - full control). It ran successfully. It made me think twice when I tried executing this feature on another machine having Contributor rights. They were not able to execute this code at all. After few hrs of research, I got to know that we need to execute this code with full control, so I made below changes to my code.


public override void ItemAdded(SPItemEventProperties properties)
{

      SPSecurity.RunWithElevatedPrivileges(delegate()
       {
                      //Your code over here...
        });
}


public override void ItemUpdated(SPItemEventProperties properties)
{

      SPSecurity.RunWithElevatedPrivileges(delegate()
       {
                      //Your code over here...
        });
}

RunWithElevatedPrivileges() will run below code with full control.

Hope this article have help you out.




Tuesday, September 4, 2012

Issues


Issue-1
I recently came to an issue where I tried deploying web part in WSP to production. I used “STSADM –o addsolution” command and my WSP got added. Then, I deployed WSP and it got deployed too but with Timer service successfully created warning. So, I tried executing this timer service with “STSADM –o execadmsvcjobs” command and it took 1 hrs to execute (and sometime 2 hrs).  Doing research I got to know that it’s because other existing WSP deployment is pending and that WSP got in pending state during deployment.

Resolution
 We need to cancel existing WSP which is in error state.

Step-by-step approach to Cancel WSP deployment
1.       Search for all WSP which are about to deployed but are in Pending state.
2.       You can see all WSP under <deployment> tags.
3.       Get Job ID of WSP which is in Pending state and cancel that WSP deployment.
4.       stsadm –o canceldeployment –id “XXXX-XXX…..”

Issue-2
Also you might face issue related to retracting solution and during retracting; solution execution takes endless time.

Resolution
You might need to delete solution directly without retracting it. Run command stsadm –o deletesolution –name “WSP-Name”. Now, add a solution and deploy solution.


Tuesday, May 29, 2012

Debug SharePoint Event Receiver Feature in Visual Studio

Quickly I will show How to debug Event Receiver Feature (Class Library) in Visual Studio 2008. When user  updates any item in List; break point will stop in Visual Studio.

Note: This post do not focus on configuring Feature.xml and Elements.xml on SharePoint server. 

Please follow below steps to attach debugger to Class Library.

  1. After you deploy DLL in GAC, Open your project.
  2. Put break point.
  3. Navigate to menu Debug -> Attach Process
  4. Search for W3WP worker process. This process start when IE browser start and open SharePoint URL. If you found multiple W3WP process then select all.
  5. That's it.
  6. Open your site on IE browser and try to update item.
Please note, break point will hit though your browser is in another box and Visual Studio is in your SharePoint Server box.

Hope this article have helped you. Enjoy SharePoint...

Friday, April 6, 2012

SharePoint Designer 2007 Workflow status as "Stopped"

Couple of occasion; workflow send mails and set the status as "Complete" and sometime workflow do not trigger mail at all and set the status as "Stopped". Reason why it "Stopped" is because; the instance of Workflow  is still using the item and workflow has checked out that item for edit.

Solution:
Wait until the workflow instance finish editing the item. Hence, use below Rules/Condition in Designer workflow

1. Create new steps.
2. Select "Wait for fields to equal value" from Action menu.
3. Click on "fields" link and Select "Checked out to" column name.
4. Click on "value" field link and choose "to be empty"
5. Above condition indicates that Workflow will execute only when item is checked in by last Workflow instance for editing.

Hope this could be useful.