Application Page Ribbon & Dialogs on SharePoint 2010

One of the cool new features in SharePoint 2010 is the availability of the Office Ribbon. Using the simple XML syntax, it is quite easy to add your own Ribbon controls and tabs to existing lists, libraries, and even your own web parts. You can even add contextual ribbon tabs to web parts hosted in your own custom Application Pages.

Now it’s easy to get a “global” Ribbon by simply omitting the RegistrationId and RegistrationType attributes in the Elements.xml file. You’ll find ways of doing this in tons of blog posts all over. What is not so obvious, however, is the way to do add a Ribbon to a particular Application Page when the page does not host any Web part or user control. So here’s some help for you. I’ll also take a look at interacting with a modal dialog using the new framework in SharePoint from this ribbon.

More...


Tags: , , ,
Categories: Development | Office | SharePoint

7 Comments
Actions: E-mail | Permalink | Comment RSSRSS comment feed

Exchange Web Services & Sending Inline Images on Exchange 2007 SP1

Microsoft recently released the Exchange Web Services Managed API SDK 1.0. This mouthful which I’ll just call EWSMAS is useful for writing custom applications that work with Exchange Server (2007 SP1 or 2010). In one of the projects we are currently working on, we need to send emails over Exchange with both normal attachments as well as inline in the mail body.

Now here’s the good thing – if you’re already on Exchange 2010, there is a simple property called IsInline that will allow you to specify the attachment as inline. However, if you’re on Exchange 2007 SP1 still (like in the case of Exchange Online/BPOS), you’re stuck as the property returns an exception stating it’s only for Exchange 2010. Here’s how to solve this problem. Note that I’ve created a simple console app to demonstrate this method only. I assume you know how to download the SDK and add reference to it in VS2008/2010.

   1:  ExchangeService service = 
   2:       new ExchangeService(ExchangeVersion.Exchange2007_SP1);
   3:   
   4:  // Use when machine is IN Domain
   5:  //service.UseDefaultCredentials = true;
   6:  //service.AutodiscoverUrl("user@domain.com");
   7:   
   8:  // Use when machine is NOT in Domain
   9:  service.Credentials = new WebCredentials("user@domain.com", "password");
  10:  service.Url = new Uri("https://Your-CAS-Server/EWS/Exchange.asmx");
  11:   
  12:  // Create an e-mail message and identify the Exchange service.
  13:  EmailMessage message = new EmailMessage(service);
  14:   
  15:  // Add properties to the e-mail message.
  16:  message.Subject = "Testing from .NET Client";
  17:   
  18:  // Add the image as inline attachment
  19:  FileAttachment attachment = 
  20:       message.Attachments.AddFileAttachment("C:\\temp\\attach.png");
  21:  attachment.ContentId = "01"; // this should be unique - say a GUID
  22:   
  23:  // Add the message body which refers to this contentID
  24:  message.Body = "Sent from a .NET with inline image <img src='cid:01'>";
  25:  message.Body.BodyType = BodyType.HTML;
  26:   
  27:  // Add recipeint
  28:  message.ToRecipients.Add("anotheruser@domain.com");
  29:   
  30:  // Send the e-mail message and save a copy.
  31:  message.SendAndSaveCopy();

Notes:

  1. Lines 5-6 should be used when the machine sending the mail is in the same AD domain as the Exchange server (say, an in-house Exchange server)
  2. Lines 9-10 should be used when the machine sending the mail is in a different AD domain from the Exchange server (say, hosted Exchange or BPOS)
  3. Line 21 is the one that sets a ContentId property for the image attachment – this will now NOT show the image as an attachment anymore. In case you need to simply add it again – this time without the ContentId.
  4. Line 24 uses this ContentId with the cid: property in a standard HTML image tag. This is what makes the image show up inline in the right place.

Inline 
This is what the inline image looks like once it is sent and received.


Tags: , ,
Categories: Development | Microsoft | Exchange

3 Comments
Actions: E-mail | Permalink | Comment RSSRSS comment feed

TechEd India 2010: PPTs, Demos & Code Snippets

I had two sessions at TechEd India 2010 – one on a lap around VS2010 Web and Cloud Development and the other on Lighting up Apps on Windows 7 using the Windows API Code Pack. The entire set of demos and content is given below. Please read to see how to use them.

The entire set is available on this SkyDrive folder. You can download the PPTs and demos for the ones you want. To create the demos yourself, you will also need to download the “Snippets” file and unzip it somewhere. Load these snippets into VS2010 using the Snippet Manager.

Open any of the projects and go through each “page” of code. You will see comments by me where you need to add some snippet. Simply type in the snippet and press tab twice to insert the appropriate code.


Tags: , , ,
Categories: ASP.NET | Development | Microsoft | Windows 7

1 Comments
Actions: E-mail | Permalink | Comment RSSRSS comment feed

Windows Phone 7 – My first app

As I unfortunately could not be at Mix 10 this year, I had to be content watching the Keynote from their live stream (which BTW worked flawlessly). Scott Guthrie as usual was outstanding and fun. And while showing off the new Windows Phone 7 developer tools went ahead and created a simple Twitter app on stage in about 5 minutes.

Well, I went ahead and downloaded the tools and installed them. Since I already had VS 2010 RC on my machine, it didn’t need to download the Express edition. It did install a bunch of other things and finally once done I went ahead and started it up.

So here’s how I beat ScottGu at his own game. I build a simple Twitter app for the Windows Phone 7 in even lesser time than him.

I created a Windows Phone application from the new project templates provided.WP7-01

Next, I changed some text around for the page and title. I also dropped in a TextBox, Button and a WebBrower control into the ContentGrid area on the phone.

WP7-02

WP7-03 I then simply added an event handler for the button’s click, like so:

webBrowser1.Navigate(new Uri("http://twitter.com/" + textBox1.Text));

That’s it. I then simply ran the application which started up the Windows Phone 7 emulator and deployed the application within it. Here’s what it looks like running.

The emulator doesn’t really have too many things in it other than Internet Explorer and some settings pages. You can of course go ahead and use the emulator to test out apps you create with Visual Studio 2010 or XNA Studio 4.0.

Here to creating great apps on Windows Phone 7. Have fun!


Tags: , ,
Categories: Development | Gadgets | Microsoft | Rave | SilverLight | Windows Phone

14 Comments
Actions: E-mail | Permalink | Comment RSSRSS comment feed

Convert/Display PDF & Word Files as Images in .NET

Recently I had to write some code as a sample to be able to display Word and Acrobat files on a Web page in a 2-page view. We couldn’t simply use a plugin or application on the user’s machine to do so. The solution was to export each page out to an image and then display the pages in any way we needed. We therefore needed to do some document export code from our application.

Word to Images

Converting Word files (.DOC & .DOCX) to images was fairly simple, although I do think I probably took a longer approach. The problem is that the older DOC format and the newer DOCX format have different APIs to work with. So instead of doing this, I simply exported them both to XPS and then used the XPS API to retrieve images for each page. This last part was not obvious to me till I found the one line of code required to do this on a forum – I apologize for not linking to this as I can’t find that link anymore. The credit for that part is wholly the original author’s.

PDF to Images

Converting PDF to images was a major issue. There is no direct way of doing this. There are many 3rd party components that are available to do this, but most of them cost a bomb. Some free ones like PDFSharp are able to iterate pages but there is no way to export a complete page to an image without walking through the entire structure of the page and redrawing everything.

This is where I found the GFLAX library. This requires GhostScript for Windows to be installed on the machine as well. You can register the DLL and then reference it in your .NET code.

Code Sample

I’m attaching the entire code sample to this post as a download. The code is released with the open source BSD license. All external components (Word and Office interop assemblies, GFL, etc.) have the copyright of their owners and must be adhered to.

Usage

Once you download the attachment and extract it, open it in Visual Studio 2008. Make sure you’ve installed GhostScript from the link above and run a “regsvr32 GFLAX.dll” for the GFLAX Library. Add reference to Microsoft.Office.Interop.Word on your machine (and remove the marked lines from Web.config) from the .NET tab and to GFLAX from the COM tab.

Run the application and upload .doc, .docx and .pdf files and you can then view them in the browser directly.

WordDisplay 
Two page display of an uploaded Word file. Works with PDF files too.

Download:
Tags: , , ,
Categories: ASP.NET | Development | Office | Tips | Download

7 Comments
Actions: E-mail | Permalink | Comment RSSRSS comment feed

WebsiteSpark and What It Means

Yesterday Microsoft made an announcement that has extremely important implications if you are into Web application development. The WebsiteSpark program offers a ton of Microsoft software for free for web developers and web development companies that qualify. You get all these software for 3 years for both development and production usage. The list of software is:

  • 3 licenses of Visual Studio 2008 Professional Edition
  • 1 license of Expression Studio 3
  • 2 licenses of Expression Web 3
  • 4 processor licenses of Windows Web Server 2008 R2
  • 4 processor licenses of SQL Server 2008 Web Edition
  • DotNetPanel control panel

You can read more about the program on Scott Guthrie’s blog post and at the main site.

What I want to explore in this post is what it means for Web development in general. Currently, there is a trend or impression that if you need to create a software for a SME, you need to use the LAMP stack to remain competitive cost-wise. While true to some extent, what you do lose out is in terms of productivity and time-to-market with tools such as VS2008 and the Expression suite. But the cost of entry to use these has often been a pitfall to getting individual Web developers or smaller Web project companies as well as for the SME.

With WebsiteSpark this so-called “advantage” of the LAMP stack goes for a toss. Not only do you get all the tools you need for free for developing projects for SME companies you also get a number of other additional options that help ease your development, such as:

  • The Web Application Toolkits: A set of pre-packaged templates, samples, source code, etc. that can be simply plugged into your site to extend it with some extra features.
  • The Web Platform Installer: Allows you to quickly set up a developer or even production machine with not just the base requirements but also a number of free Web Applications such as WordPress, Umbraco, SugarDRM, DotNetNuke, Moodle etc. by simply following the setup prompts. Take a look at the Web Application Gallery and see how easy it is to setup these without having to mess around with configuration files and database connection settings on Windows.

This basically means that setting up and using Windows as a platform for Web application development not only is easier and faster but also is now available for free! You can also run most of the open source Web apps on Windows with better performance and scalability. So is there any real reason to still go for the LAMP stack? Try the above stuff out and then decide.


Tags: , , , ,
Categories: ASP.NET | Development | Internet | Microsoft | Rave

12 Comments
Actions: E-mail | Permalink | Comment RSSRSS comment feed

Three Articles in August 2009 PCQuest

PCQuest has just published 3 of my articles in their current issue. It was actually supposed to be 4, but the one on ASP.NET 4 got lost in the mail and a resend was received too late for this issue. You can read these articles here:

I’m also going to try and compile a list of articles I’ve written in PCQuest over the last few years and link to them here.


Tags: , , , ,
Categories: Windows 7 | SilverLight | Office | Development | ASP.NET

4 Comments
Actions: E-mail | Permalink | Comment RSSRSS comment feed

Loading Child Table Data in SilverLight & RIA Services

I’m currently working with the .NET RIA Services SDK with Silverlight 3 for getting and modifying data from the server using LINQ. Now there are a ton of samples and blog posts available that show you how to work with data from the server. However, one thing in common with all these posts is that they usually work with only one table at a time. What if you want to show the result of a join on the table? This is where a relatively unknown feature called the IncludeAttribute comes in. Let’s take an example for this to explain it in detail.

More...


Tags: , ,
Categories: Development | Tips | SilverLight

7 Comments
Actions: E-mail | Permalink | Comment RSSRSS comment feed

SilverLight 3.0 Out of Browser Mini Tutorial

SilverLight 3.0 has just been released to the web. And there is now an even more important reason to start using this great technology – running apps written for the browser can now be run as a standalone application from the user’s desktop as well. This post takes a detailed look at how you can start using this new feature. More...


Tags: , ,
Categories: Development | SilverLight

5 Comments
Actions: E-mail | Permalink | Comment RSSRSS comment feed

Windows 7 and Application Compatibilty

I’m updating my blog after a long time since I’ve been tied up in doing a large number of Windows 7 Application Compatibility workshops all across India with a number of Independent Software Vendors (ISVs) for their products. We’re basically testing out their products on the Windows 7 RC to see any issues that might surface and what they need to do to resolve them.

Most application run just fine on Windows 7. However, in the cases where there is an issue, it almost invariably turns out that the product has not been tested on Windows Vista and therefore it also fails on Windows XP. Vista and 7 have a tighter security mechanism called UAC that needs to be addressed in applications – and is something that many developers face problems with.

So here are two of the biggest issues that I’ve seen and their solutions: More...


Tags: , ,
Categories: Windows 7 | Tips | Development

8 Comments
Actions: E-mail | Permalink | Comment RSSRSS comment feed