Monday, October 24, 2011

Adding Custom Context Menu Item to Edit Control Block in SharePoint 2010

Within SharePoint 2010, there is a ‘context menu’ that is shown when you click on a specific file – eg. DOCX.
image
This is actually known as the “Edit Control Block” or ECB. Yep – another acronym for the kitbag.
To add functionality to the SharePoint 2010 ECB, we have to create a new SharePoint feature, with some XML within an ELEMENTS.XML file.
Here’s the steps to follow :
  • Open Visual Studio 2010
  • Click on “Empty SharePoint Project”
  • Name the project : NewContextMenuButton
  • Choose to ‘deploy as a farm solution’ when prompted
Within the new project, we need to add a new ‘elements’ file – and subsequent feature, etc.
  • Right-click on the project, and choose Add > New Item
  • Choose ‘Empty Element’
  • Enter the name as : NewContextMenuButton
  • Click CTRL+A (select all) and then Delete.
  • Paste in the following XML
<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”>
<CustomAction Id=”SPR.CustomButton”
RegistrationType=”FileType”
RegistrationId=”docx”
Location=”EditControlBlock”
ImageUrl=”/_layouts/IMAGES/DOCLINK.GIF”
Sequence=”600″
Title=”Custom Button”
Description=”Click this button to see something magical occur…” >
<UrlAction Url=”javascript: alert(‘Hello World !’)” />
</CustomAction>
< /Elements>

You can now simply right-click – and choose DEPLOY – that’s it…! The feature & package name will be the default values – but they can be changed if needed.
Also – the IMAGE being used was just something that I found in the ‘layouts’ area of SharePointRoot.
Here’s the new Context Menu item – sorry, new addition to the Edit Control Block :
image
This will create a new entry for “DOCX” files – based on the “RegistrationType”.

Create rich HTML email message in Sharepoint Designer 2010 workflow


The Sharepoint designer 2010 workflow email body action is not a rich HTML, its not supported with this version but i found a quick way to add rich HTML in email body message.
Here is the steps:
  • First create your HTML in dreamweaver or vs2010 or any other HTML editing tool
  • Then open your workflow in SPD 2010
  • Add “Send email” workflow action from ribbon
  • Keep “Send Email” action selected/highlighted
  • Then navigate to ribbon and select advanced properties
  • Select last option Body
  • Click on the button (...) to open the text pad
  • paste your html including head,body and html.
  • Click OK and open the action from workflow step
  • Then add your lookups and test it.
  • Done!

Friday, October 21, 2011

Custom Blog Rollup Using Content Query Web Part


There are a few posts dealing with CQWP customization but most of them use the publishing pages. A few requests have been posted to customize blog posts using CQWP and there is something specific to this request: the CQWP does not output the blog post body out of the box. Before I describe the process, I should give credit to the blog post by Heather Solomon (2007, but still valid for 2010).
There are two main steps in this process: customize the ItemStyle and the CQWP. You can find the reference on adding properties to the CQWP at this MSDN article.
So, we export the CQWP and edit the line that has CommonViewFields to become <property name=”CommonViewFields” type=”string”>Body, Note</property>
Here, Body is the post body text and Note is its type (yes, it’s not RichHtml as you may think), but how do we know? You check the schema file at \14\TEMPLATE\FEATURES\DiscussionsList\Discuss
Now that we have the field available in the CQWP, we edit the item style. The ItemStyle.xsl file lives in the Style Library in your site collection (only there, one style library per site collection) inside the folder XSL Style Sheets (that’s easy to figure out). You download the file and open it in a text or xml editor. Here, we will copy the default style and paste it under the original (starts with <xsl:template name=”Default” match=”*” mode=”itemstyle”> and ends with </xsl:template> – around 67 lines). Of course, we need to name our style – I replaced the first line by <xsl:template name=”AKTemplate” match=”Row[@Style='AKTemplate']” mode=”itemstyle”> You will notice we have a few blocks of xsl variables and I added my new one under the last one (Display Title)
<xsl:variable name=”bodyContent”>
<xsl:call-template name=”removeMarkup”>
<xsl:with-param name=”string” select=”@Body”/>
</xsl:call-template>
</xsl:variable>
We will get back to the removeMarkup soon (I used the same one by Heather).
The code starting with <div class=”item”> is where we show the data, so I added
<div class=”description”>
<xsl:value-of select=”substring($bodyContent,1,75)”/> … (<a href=”{$SafeLinkUrl}” mce_href=”{$SafeLinkUrl}” target=”_blank” title=”{@LinkToolTip}”>More</a>) </div>
</div>
just before the last </div> in that block (close to the end of the template). Here, I am taking the first 75 characters of the clean text and added a link to see the full post.
Finally, I added the template that strips out html tags right after the closing tag of my custom template (</xsl:template>). The removeMarkup template is available from Heather’s post toward the end and is clearly marked.
Save the xsl file and re-upload to the styles library (xsl style sheets folder). You need to publish a major version for this to work (not only check it in).
Now, you add a web part to your page based on the exported and adjusted one (under the web part groups, locate the Upload web part then select from imported web parts). Configure your CQWP and select your new item style (do not add Body; in the Description field!). If you did not have typos, you should see something similar to the above screen shot. If your itemstyle is not correct, your CQWP will not show and will give error (add ?contents=1 to the url and delete it, then roll back to the previous version of the itemstyle until you fix the custom one). See more on Heather’s blog on how to see available fields and find types etc.

Thursday, October 20, 2011

Send e-mail in a SharePoint Designer Workflow with dynamic string and images.

Send e-mail in a workflow with dynamic string and images.

We can create Email body with HTML tags to build a dynamic string

MOSS 2007
 Eg: Please find the Item URL: <a href="http://<sharepoint site>/Lists/Anouncements/dispform.aspx?ID=[%Current Item:ID%]">Announcement Item</a>

To have images in e-mail body we can use IMG HTML tag. Store image in your site sitecollection images library and copy the exact URL of image.

<img src="http://<Sharepoint site>/SiteCollectionImages/test.jpeg"/>


http://office.microsoft.com/en-us/sharepoint-designer-help/send-e-mail-in-a-workflow-HA010239042.aspx



SharePoint 2010:


Open the add a Hyper link Icon and Enter Text to Display and Address of the URL as

http://<sharepoint site>/Lists/Anouncements/dispform.aspx?ID=[%Current Item:ID%]. This will create a Dynamic URL in the Email Body.




Happy SharePointing !!!

Wednesday, October 19, 2011

Creating custom views on Survey in Sharepoint

For other lists within sharepoint we have an option of
creating our own custom views.


(Settings-CreateView).

However we have no such option in case of Survey. To create
our own custom view in case of survey we can do the following


First get the id of your survey. For this select view source
of the following page



You can get the id of the survey at following line

href=”/_layouts/listfeed.aspx?List=545889cc%2D1be0%2D463d%2Dbaa2%2D6dbec360ba68″

The id of the survey list is – 545889cc%2D1be0%2D463d%2Dbaa2%2D6dbec360ba68

Or

545889cc-1be0-463d-baa2-6dbec360ba68


%2D is equal to -


Now we need the url where in we
will use the above list id for creating custom view

For this create a simple IssueTracking
list or any other list for which we have an option of creating custom view.

Now select setting–>create
view for that newly created list


Copy the url

http://servername:12345/_layouts/ViewType.aspx?List==%7B59C5C613%2D11FB%2D44D8%2DB29E%2DC973006C062A%7D&

Source=http%3A%2F%2Fd%2D1246%3A12345%2FLists%2FDemo%2520tasks%2FAllItems%2Easpx



Get this much part of the url


http://servername:12345/_layouts/ViewType.aspx?List==%7B59C5C613%2D11FB%2D44D8%2DB29E%2DC973006C062A%7D



%7B is equal to {


%7D is equal to }



Modify it in the following manner


http://servername:12345/_layouts/ViewType.aspx?List={545889cc%2D1be0%2D463d%2Dbaa2%2D6dbec360ba68}



or 



http:// servername:12345:12345/_layouts/ViewType.aspx?List={545889cc-1be0-463d%2Dbaa2-6dbec360ba68}


i.e replace the list id.


Now you should be able to create your own custom views on surveys.


This is an Excellent job by  Nishant Rana.

Tuesday, October 11, 2011

Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Error: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Cause of Error:
When we call Response.Redirect("") from try/catch block in asp.net, you will receive above error.
 
Example contains error:
try
{
string strRedirectUrl = Session["ReturnUrl"].ToString();
Response.Redirect(strRedirectUrl);
}
catch(Exception ex)
{
Response.Redirect("Default.aspx");
}


Solution:
Make second argument of response.redirect("MyPage.aspx",false);
Example containing solution:
try
{
string strRedirectUrl = Session["ReturnUrl"].ToString();
Response.Redirect(strRedirectUrl,false);
}
catch(Exception ex)
{
throw ex;
}
 

Thursday, October 6, 2011

People Picker Control in VS2010 to get the SharePoint Users Email

Using People Picker Control in VS2010 to get the SharePoint Users Email, First Name,.......etc.

Use the following tag in your Visual Web part user control
<SharePoint:PeopleEditor ID="myPeoplePicker" runat="server" SelectionSet="User" />
To access the user email id entered in the control, use the following code
PickerEntity pckEntity = (PickerEntity)myPeoplePicker.ResolvedEntities[i];
string email = pckEntity.EntityData["Email"].ToString();
 
http://karinebosch.wordpress.com/sharepoint-controls/peopleeditor-control/
 Thanks to Karine Bosch! 
 
Happy SharePointing!!!.