C# Fax - Query Submitted Faxes Using FaxQuery2

Download the C# fax API zip file.

The FaxQuery2 method demonstrated in this sample allows you to display detailed information for a number of previously-submitted C# faxes. FaxQuery2 provides more advanced querying options than FaxQuery (for more details, see Side-by-Side Comparison of Web Service Methods).

In the C# fax code snippet below, detailed information is displayed for a number of faxes previously submitted to the InterFAX Web service:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FaxQuery2
{
    class Program
    {
        static void Main(string[] args)
        {
            string username = "";
            string password = "";
            interfax.QueryForm queryForm = new interfax.QueryForm();
            // intialises a form on which you can specify the desired query parameters
            // subject
            queryForm.Subject = new interfax.QueryCondition();
            queryForm.Subject.Verb = interfax.SQLOperatorEnum.Equals;
            queryForm.Subject.VerbData = "";
            // fax number
            queryForm.FaxNumber = new interfax.QueryCondition();
            queryForm.FaxNumber.Verb = interfax.SQLOperatorEnum.Equals;
            queryForm.FaxNumber.VerbData = "";
            // date from and to
            queryForm.DateFrom = new DateTime(1980, 1, 1);
            queryForm.DateTo = new DateTime(2080, 1, 1);
            // user ID
            queryForm.UserID = new interfax.QueryCondition();
            queryForm.UserID.Verb = interfax.SQLOperatorEnum.Equals;
            queryForm.UserID.VerbData = "";
            // reply address
            queryForm.ReplyAddress = new interfax.QueryCondition();
            queryForm.ReplyAddress.Verb = interfax.SQLOperatorEnum.Equals;
            queryForm.ReplyAddress.VerbData = "";
            // transaction ID
            queryForm.TransactionID = new interfax.QueryCondition();
            queryForm.TransactionID.Verb = interfax.SQLOperatorEnum.Equals;
            queryForm.TransactionID.VerbData = "546585833";
            // parent transaction ID (for batches)
            queryForm.ParentTransactionID = new interfax.QueryCondition();
            queryForm.ParentTransactionID.Verb = interfax.SQLOperatorEnum.Equals;
            queryForm.ParentTransactionID.VerbData = "546585833";
            // status ( 0 is successfull, for others, see error code list)
            queryForm.Status = new interfax.QueryCondition();
            queryForm.Status.Verb = interfax.SQLOperatorEnum.Equals;
            queryForm.Status.VerbData = "0";
            // show hidden transaction ids 
            queryForm.ShowHiddenTransactions = true;
            // end of query conditions form
            interfax.QueryControl queryControl = new interfax.QueryControl();
            // initialises a form which controls settings for the query made
            // only display broadcast transaction ids
            queryControl.OnlyParents = false;
            // number of transaction ids returned, maximum is as per system limitations
            queryControl.NumOfResults = 1;
            // start displaying results beginning with this transaction id
            queryControl.StartingRecord = 0;
            queryControl.OrderBy = interfax.OrderByColumnEnum.TransactionID;
            // sort ascending ?
            queryControl.AscOrderDirection = false;
            // full fax details returned ?
            queryControl.ReturnItems = true;
            // display statistical information regarding success/failure/error types returned
            queryControl.ReturnStats = true;
            //end of query settings form
            interfax.InterFax interfaxWebServiceOutbound = new interfax.InterFax();
            interfax.FaxQueryResult resultStatus = interfaxWebServiceOutbound.FaxQuery2(username, password, queryForm, queryControl);
            if (resultStatus.ResultCode == 0) // if it is successfull, display the results of the query
            {
                if(resultStatus.TotalTransactionsNum != 0) // if there are results to display
                {
                    Console.WriteLine(string.Format("Found {0} result(s).", resultStatus.TotalTransactionsNum)); //verbose
                    Console.WriteLine(string.Format("Displaying Results : "));
                    for (int i = 0; i <= resultStatus.FaxItems.Length - 1; i++)
                    {
                        Console.WriteLine(string.Format("============{0}============", i + 1));
                        Console.WriteLine(string.Format("Username: {0}", resultStatus.FaxItems[i].UserID));
                        Console.WriteLine(string.Format("TransactionID: {0}", resultStatus.FaxItems[i].TransactionID));
                        Console.WriteLine(string.Format("DestinationFax: {0}", resultStatus.FaxItems[i].DestinationFax));
                        Console.WriteLine(string.Format("SubmitTime: {0}", resultStatus.FaxItems[i].SubmitTime));
                        Console.WriteLine(string.Format("PostponeTime: {0}", resultStatus.FaxItems[i].PostponeTime));
                        Console.WriteLine(string.Format("CompletionTime: {0}", resultStatus.FaxItems[i].CompletionTime));
                        Console.WriteLine(string.Format("Duration: {0}", resultStatus.FaxItems[i].Duration));
                        Console.WriteLine(string.Format("Subject: {0}", resultStatus.FaxItems[i].Subject));
                        Console.WriteLine(string.Format("Reply Email: {0}", resultStatus.FaxItems[i].ReplyEmail));
                        Console.WriteLine(string.Format("Sender CSID: {0}", resultStatus.FaxItems[i].SenderCSID));
                        Console.WriteLine(string.Format("Remote CSID: {0}", resultStatus.FaxItems[i].RemoteCSID));
                        Console.WriteLine(string.Format("Pages Submitted: {0}", resultStatus.FaxItems[i].PagesSubmitted));
                        Console.WriteLine(string.Format("Pages Sent: {0}", resultStatus.FaxItems[i].PagesSent));
                        Console.WriteLine(string.Format("Status: {0}", resultStatus.FaxItems[i].Status));
                    }
                }
                else // no results
                {
                    Console.WriteLine(string.Format("There are no results to display matching your query."));
                }
            }
            else // if it is an error, provide the error code
            {
                Console.WriteLine(string.Format("Error Code {0}.", resultStatus.ResultCode));
            }
            Console.ReadLine(); // use this to keep console open (waiting for keypress) after it is finished
        }
    }
}

Contact us today

Talk to a member of our team about the benefits InterFAX can bring to your organization's communications processes.

Contact us today