3 Replies - 800 Views - Last Post: 09 December 2013 - 08:59 AM Rate Topic: -----

#1 ecarter202   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 29
  • Joined: 02-September 12

How to print a resource documet

Posted 08 December 2013 - 03:11 PM

I have grabbed the code from the following link
PrintDocument Class MSDN
and only modified the source it's printing.

It works fine with a local text document path, but I have added a .txt resource and it throws the following error when I try to print it...

Posted Image


Thank you!

Is This A Good Question/Topic? 0
  • +

Replies To: How to print a resource documet

#2 AdamSpeight2008   User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Re: How to print a resource documet

Posted 08 December 2013 - 03:17 PM

There is illegal characters in your path. Without seeing that path, I can only suggest that you check to see what are and ain't legal characters in a path or URL name.
Was This Post Helpful? 1
  • +
  • -

#3 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7457
  • View blog
  • Posts: 25,100
  • Joined: 05-May 12

Re: How to print a resource documet

Posted 09 December 2013 - 06:55 AM

Your StreamReader needs to get the resource as a stream instead of passing in the resource name.

So instead of this from MSDN:
streamToPrint = new StreamReader
               ("C:\\My Documents\\MyFile.txt");



You would do:
var assembly = Assembly.GetExecutingAssembly(); // change to assembly that has the resource
var resName = "Your.Namespace.MyFile.txt"; // change to namespace qualified resource name
streamToPrint = new StreamReader
               (assembly.GetManifestResourceStream(resName));


Was This Post Helpful? 1
  • +
  • -

#4 ecarter202   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 29
  • Joined: 02-September 12

Re: How to print a resource documet

Posted 09 December 2013 - 08:59 AM

View PostSkydiver, on 09 December 2013 - 06:55 AM, said:

Your StreamReader needs to get the resource as a stream instead of passing in the resource name.

So instead of this from MSDN:
streamToPrint = new StreamReader
               ("C:\\My Documents\\MyFile.txt");



You would do:
var assembly = Assembly.GetExecutingAssembly(); // change to assembly that has the resource
var resName = "Your.Namespace.MyFile.txt"; // change to namespace qualified resource name
streamToPrint = new StreamReader
               (assembly.GetManifestResourceStream(resName));



Awesome! I appreciate the help!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1