Can I use document providers in non silverlight applications?

3 posts, 1 answers
  1. Sean Cross
    Sean Cross avatar
    37 posts
    Member since:
    Oct 2009

    Posted 30 Jul 2012 Link to this post

    I would like to use the document providers server side so I can manipulate Word documents.  Is there anyway to do this in a non-silverlight assembly? 

    Searching the forums suggests that it's possible but I can't get it to work.  I get the error "Could not load file or assembly 'System.Windows, Version=5.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified."

    Is there any way to make this work?
  2. Answer
    Martin Ivanov
    Admin
    Martin Ivanov avatar
    104 posts

    Posted 31 Jul 2012 Link to this post

    Hello Sean,

    You cannot use the Silverlight assemblies in a non-Silverlight application; however you can use the WPF version of the providers in most applications (WPF, Console Applicaitons, ASP.NET).

    The only thing you should make sure is that the method is in a Single-Thread Apartment state.

    [STAThread]

    Here is an example how you can use the format providers in a console application to convert docx documents to PDF.

    class Program
       {
           [STAThread]
           static void Main(string[] args)
           {
               string loadFrom = "../../../demoDocument.docx";
               string writeTo = "../../../exportedDemoDocument.pdf";
               Convert(loadFrom, writeTo);
           }
     
           public static void Convert(string docxFilePath, string pdfFilePath)
           {
               RadDocument document = null;
     
               // Load Docx
               IDocumentFormatProvider docxFormatProvider = new DocxFormatProvider();
               using (FileStream docxStream = File.Open(docxFilePath, FileMode.Open))
               {
                   document = docxFormatProvider.Import(docxStream);
                   document.EnsureDocumentMeasuredAndArranged();
               }
     
               // Save Pdf
               IDocumentFormatProvider pdfFormatProvider = new PdfFormatProvider();
               using (FileStream pdfStream = File.Open(pdfFilePath, FileMode.Create))
               {
                   pdfFormatProvider.Export(document, pdfStream);
               }
           }
       }

    Don't hesitate to contact us if you have other questions.

    Kind regards,
    Martin
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Sean Cross
    Sean Cross avatar
    37 posts
    Member since:
    Oct 2009

    Posted 31 Jul 2012 Link to this post

    Thanks, that did it.
Back to Top