Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Print an xml file
Message
From
22/01/2016 08:26:33
Metin Emre
Ozcom Bilgisayar Ltd.
Istanbul, Turkey
 
 
To
21/01/2016 17:49:20
General information
Forum:
Visual FoxPro
Category:
Third party products
Miscellaneous
Thread ID:
01630017
Message ID:
01630075
Views:
143
Thank You All,

But this's not an ordinary xml. Actually this's an electronic invoice and when you open it in any browser you'll see a well formatted invoice. So type with dos command doesn't work. Of course I know a lot of ways to print ordinary text files with VFP and Axapta. But just browsers can handle this files. So I had suggested a way from another form, and that solved my problem:

https://msdn.microsoft.com/en-us/library/b0wes9a3%28v=vs.110%29.aspx

We created a .NET exe and worked almost excellent. Just one thing. Our .NET application doesn' quit. If we try to quit, it doesn't print:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            foreach (string arg in args)
            {
                //PrintHelpPage(arg);
                Uri uri = new Uri(arg);
                runBrowserThread(uri);

            }

           // Environment.Exit(0);
        }

        private static void PrintHelpPage(string path)
        {
            // Create a WebBrowser instance. 
            WebBrowser webBrowserForPrinting = new WebBrowser();

            // Add an event handler that prints the document after it loads.
            webBrowserForPrinting.DocumentCompleted +=
                new WebBrowserDocumentCompletedEventHandler(PrintDocument);

            // Set the Url property to load the document.
            webBrowserForPrinting.Url = new Uri(path);
        }

        private static void PrintDocument(object sender,
            WebBrowserDocumentCompletedEventArgs e)
        {
            // Print the document now that it is fully loaded.
            ((WebBrowser)sender).Print();

            // Dispose the WebBrowser now that the task is complete. 
            ((WebBrowser)sender).Dispose();


        }

        private static void runBrowserThread(Uri url)
        {
            var th = new Thread(() =>
            {
                var br = new WebBrowser();
                br.DocumentCompleted += PrintDocument;
                br.Navigate(url);
                Application.Run();
            });
            th.SetApartmentState(ApartmentState.STA);
            th.Start();
        }

        void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            var br = sender as WebBrowser;
            if (br.Url == e.Url)
            {
                Console.WriteLine("Natigated to {0}", e.Url);
                Application.ExitThread();   // Stops the thread
            }
        }
    }
}
>foxpro codes below:
>any xml file is a simple txt file ( as prg,html,...)
>notepad can open this file (as IE,FF or any navigator).
>
>can use this vfp syntax:(see foxHelp)
>TYPE FileName1 [AUTO] [WRAP] [TO PRINTER [PROMPT] | TO FILE FileName2] [NUMBER]
>
>or simply Type getfile('xml') to printer
>
>
>another light way to print directly an xml file is to print it with notepad command line (/p)
>(wordpad /p does the same thing also).
>
>
>local m.lcfile
>m.lcfile=getfile('xml')
>if empty(m.lcfile)
>return .f.
>endi
>run/n notepad /p  &lcfile
>
>
>the API shellexecute (0,"print",getfile('xml'),"","",0) dont work because there is no association
>with the print verb and the xml files.
>
>
>it returns a result value<=32 want to say fails.
>
>
>you can invoke the commondialog print with sending keys
> keyboard "{CTRL+P"}
>
>or
>
> creating com object "(mscomdlg.commondialog") prompt or no prompt.
>
>you can use IE oleBrowser with
>
>
>#DEFINE OLECMDID_PRINT 6
>#DEFINE OLECMDID_PRINTPREVIEW 7
>#DEFINE OLECMDEXECOPT_DODEFAULT 0
>#DEFINE LECMDEXECOPT_DONTPROMPTUSER 2
>apie=newObject("internetexplorer)
>with apie
>......
>.Execwb(OLECMDID_PRINT  ,LECMDEXECOPT_DONTPROMPTUSER )  
>.......
>.quit
>endwith
>
>
>warning: IE have changed some old behaviors depending what IE version used.
>
>Can also use old CMD.exe to print a file by directing it to the printer
>i dont know if this yet work in dos cmd window:
>
>
>type "filename.txt" >lpt1:
>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform