This is a migrated thread and some comments may be shown as answers.
Can I use document providers in non silverlight applications?
2 Answers 24 Views
This is a migrated thread and some comments may be shown as answers.
Sean Cross
Top achievements
Rank 1
Sean Cross asked on 31 Jul 2012, 04:00 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 31 Jul 2012, 12:34 PM
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.

0
Sean Cross
Top achievements
Rank 1
answered on 01 Aug 2012, 01:35 AM
Thanks, that did it.
Asked by
Sean Cross
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Sean Cross
Top achievements
Rank 1
Share this question
or