Friday, January 11, 2013

FREE course & exam: Developing in HTML5 with JavaScript and CSS3 Jump Start

This course provides an accelerated introduction to HTML5, CSS3, and JavaScript and helps students gain basic HTML5/CSS3/JavaScript programming skills. This course is an entry point into both the Web application and Windows Store apps training paths and helps prepare learners for Microsoft exam 70-480. The course focuses on using HTML5/CSS3/JavaScript to implement programming logic, define and use variables, perform looping and branching, develop user interfaces, capture and validate user input, store data, and create well-structured applications.
This course is also useful for developers of SharePoint-hosted Apps.

FREE EXAM VOUCHER FOR 70-480! | Register now to take Exam 70-480 Programming in HTML5 with JavaScript and CSS3 for FREE! Just use this voucher code when scheduling your exam: HTMLJMP (promotion code available through 3/31/2013 or while supplies last.)

Free ebooks on HTML, CSS, and JavaScript.

InfoPath: Managed code (C#) to convert view to Html

I've been looking for code snippets to be able to convert an Infopath view to Html and then use a converter service to create a PDf document. The form is published via InfoPath Forms Services so the export to PDF function is not available.

Inspired by the snippets I've found, I ended up with a nice piece of lean and mean code:

public void CreatePDF_Clicked(object sender, ClickedEventArgs e)
{
 // Create HTML.
 try
 {
  string sourceFileName = null;
  byte[] sourceFile = null;
  
  XPathNavigator root = MainDataSource.CreateNavigator();
  string myViewName = this.CurrentView.ViewInfo.Name;
  string myViewXslFile = myViewName + ".xsl";

  XslCompiledTransform transform = new XslCompiledTransform();
  transform.Load(ExtractFromPackage(myViewXslFile));
  
  // Generate a temporary HTML file
  string fileName = Guid.NewGuid().ToString() + ".htm";
  string filePath = Path.Combine(Path.GetTempPath(), fileName);
      
  using (XmlWriter writer = XmlWriter.Create(filePath))
  {
   // Convert the XML to HTML
   transform.Transform(root, writer);
   // writer.Close();
  }

  // Specify the HTML to convert
  sourceFile = File.ReadAllBytes(filePath);
 
  //** etc...
 
 }
 catch
 {
 }
}  
    
public XmlDocument ExtractFromPackage(string fileName)
{
 try
 {
  XmlDocument doc = new XmlDocument();

  using (Stream stream = Template.OpenFileFromPackage(fileName))
   doc.Load(stream);

  return doc;
 }
 catch (Exception ex)
 {
  throw new Exception(string.Format("Error extracting '{0}': {1}",
   fileName, ex.Message), ex);
 }
}

Hereby assuming that the name of the (current) view is equal to the name of the .xsl file in the XSN package.


How to convert Html to PDF:

TIP: Eighth edition of the free DIWUG SharePoint Magazine

DIWUG SharePoint e-Magazine #8

In this edition:
  • Social in SharePoint Online 2013 - Jasper Oosterveld
  • Managed Metadata Driven Menus - Chris Grist
  • Implementing Effective Governance Plans for Microsoft SharePoint - Anne Plancius
  • The Discovery Center in SharePoint Server 2013 - Gustavo Velez
  • Document Sets: The Improved Folder? - Ronald Laan
  • Business Connectivity Services, beyond the box - Matthias Fonteyne, Lynn Franceus, Niels De Winde
  • SharePoint Web Templates - Mirjam van Olst

The DIWUG SharePoint eMagazine is a free downloadable magazine with articles written by MCMs, MVPs and other authors from the SharePoint community. The target audiences are IT-pros, developers and end (power) users.