Link to home
Start Free TrialLog in
Avatar of Stephen Forero
Stephen ForeroFlag for United States of America

asked on

Print Document in Lotus Notes using C#

Hi guys... I'm still new to this but basically I am going to the last email in my "sent" folder, and wanting to print it.

So far I was able to find the last email in folder, but can't print it, any help would be GREATLY appreciated.!!!!
thanks!!!

private void PrintLastEmail()
{
//Lotus Notes Object Creation
NotesSession _notesSession = new NotesSession();
NotesDatabase _notesDataBase = null;
NotesDocument _notesDocument = null;
string sServerName =comboBox1.Text;//"NJROS1NML45/SERVER/Prudential"; //ConfigurationManager.AppSettings["NJROS1NML45/SERVER/Prudential"];
string sMailFile = "/Mail/" + login + ".nsf"; //"/Mail/x152169.nsf"; 
string password = login; //ConfigurationManager.AppSettings["x152169"];
object oItemValue = null;
_notesSession.Initialize(password);
_notesDataBase = _notesSession.GetDatabase(sServerName, sMailFile,
false);
//If the database is not already open then open it. 
if (!_notesDataBase.IsOpen)
{
_notesDataBase.Open();
}

Open in new window

Avatar of wuesten_fuchs
wuesten_fuchs
Flag of Germany image

The code you list seems to be incomplete. But as far as I can see, you are using Notes backend classes which is all that is available to Java. Printing, however, is a function in the frontend (UI) Notes classes and these are only available to LotusScript (or COM).
Avatar of Sjef Bosman
Your options for "back-end" printing in C# are limited:
- use Word, via COM
- use some PDF toolkit (available in Java or LotusScript)
- use the HTTP-interface to read the mail as a web page

The last option at least uses the mail form to display the mail. The others don't even do that.
Avatar of Stephen Forero

ASKER

Apologies, as I am still new to this. What is the difference between back end classes, and front end classes.

I was also under the impression everything I was using was from the COM library.

It is not important for me to see the email before printing.  Which route do you recommend that I go that will be the easiest for me to figure out? So far the only real experience I have is in VBA.

One thought I have was create a small print code in lotusscript(because I hear its similar to VBA), then call that code from c#.

Also, I am using visual studio express c# 2010

Thanks again for all the contidued input!!
SOLUTION
Avatar of wuesten_fuchs
wuesten_fuchs
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
How can I tell if something is available in com or lotusscript.

If I go the webpage route, how do I go about starting it. Do I have to learn a new language?
The availability of all classes is documented in the standard Domino Designer online help ...

By the way, perhaps you can tell us a bit more about your intention why you want to print the last sent message? Perhaps it gives us enough information to suggest even other solutions.
Basically I have a program that emails something automatically. I goal is to have the email that was created and sent, printed automatically
Well, now, I have limited C# knowledge (zero actually), so I'd have to guess a little.

Approach:
- use your actual code
- get the UniversalID of the document you found
- use an HTTPRetriever to retrieve the page using the url:
      "http ://www.dnsname.xyz/path/dbname.nsf/0/universalID
- you will be prompted for name and password (unfortunately)
- I assume the web page you retrieved is printable

Example of a way to retrieve a page: http://stackoverflow.com/questions/598075/how-to-retrieve-a-webpage-with-c
Promtpted for username and pw I do not think would be acceptable unfortunatelly
Right... You didn't set up SSO? Well, in that case: forget it.
I do not know what sso is?
Sso ssorry :-))  

Single Sign-On: log on once, valid for multiple servers.

http://www-10.lotus.com/ldd/dominowiki.nsf/dx/03202009124501PMCSAMLM.htm
So when I setup this sso, it will use the password from logging into the mail server to find it as a webpage? Is that the concept behind it?

wuesten_fuchs,
If I go the lotusscript way... is it possible to have c# call the small section of lotusscript code that prints.... basically keeping 99% of my program in c#.


sjef_bosman,
If I got the webpage... its as easy as what you said above to find it:
Approach:
- use your actual code
- get the UniversalID of the document you found
- use an HTTPRetriever to retrieve the page using the url:
      "http ://www.dnsname.xyz/path/dbname.nsf/0/universalID


I found some a link that shows how to print from html in c#... does this look like what I would use to accomplish this?  And if I go this way... I have to wait for page to load before it actually prints I'm assuming.
http://http://www.codeproject.com/KB/printing/printhml.aspx
No. LotusScript code that contains references to UI classes must be called from within the Lotus Notes client.

I wonder why you make that all so complicated ...

If you want to send e-mail from an external program through your (apparently) Lotus Domino server, then why don't you simply submit it via SMTP by using a command line tool like (for example) blat (www.blat.net).

If you then want to get any such sent message automatically printed, too, then simply CC it to a separate (local) mailbox on your Domino server. Then use a tool like mailprint (www.mail-print.com) to print everything that arrives to this mailbox (this tool reads it via POP3 and prints it, even including attachments). Yes, mailprint is not free, but it is cheap compared to the many hours you could spend reinventing the wheel.
I think the web-page route is the only more or less feasible route. Even trying to activate some LotusScript-code from C# won't work, because that code cannot use front-end calls, for which an open and active Notes-client is absolutely necessary. But only you can prove that the route you choose work for you. I certainly hope it does!
so I tried
using System.Net.WebClient class.
System.Console.WriteLine(new System.Net.WebClient().DownloadString(url)); 

Open in new window


and I am getting the following error
The remote server returned an error: (407) Proxy Authentication Required.

found this
This is a very common error message when you try to get a resource on internet through your application. Why you getting this error from your application not from explorer. The reason is very simple either you use LAN that requires proxy setting or you use proxy server.

Example :
DataSet myds = new DataSet();
//Set the system proxy with valid server address or IP and port.
System.Net.WebProxy pry = new System.Net.WebProxy("172.16.0.1",8080);
//The DefaultCredentials automically get username and password.
pry.Credentials = CredentialCache.DefaultCredentials;
GlobalProxySelection.Select = pry;
myds.ReadXml("http://msdn.microsoft.com/netframework/rss.xml", XmlReadMode.Auto);
myds.WriteXmlSchema(@"c:\\f.xml");
this.GridView1.DataSource = myds.Tables[2];
this.GridView1.DataBind(); 

Open in new window


had to change globalproxyselection to //WebRequest.DefaultWebProxy = pry;

and I am getting errors on Gridview
Error      1      'frmMain' does not contain a definition for 'GridView1' and no extension method 'GridView1' accepting a first argument of type 'frmMain' could be found (are you missing a using directive or an assembly reference?)      H:\SAVED\frmMain.cs      1112      14      OTCAutomation


ideas?
You don't give us much to go with, two lines of (copied) code and an error. My crystal ball stays clouded, sorry...

There is a C#-Zone, why don't you ask for this question to be added to that zone?
I was able to retreive webpage through proxy but now need assistance printing it in a nice format.

I also posted in c# area

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
     public void FindWebPage()
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.msn.com");
        WebProxy myproxy = new WebProxy("http://autoproxy:81", false);
        myproxy.BypassProxyOnLocal = false;
        request.Proxy = myproxy;
        request.Method = "GET";
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();


System.IO.Stream _WebStream = response.GetResponseStream(); 

Open in new window

For a nicer format you may have to modify the HTML and/or the CSS. How "nicer" do you want to have it??