I'm trying to write a program that will send faxes to the Windows Fax system but I am having problems with the COM library FaxComEx.
My code:
try
{
var faxServer = new FAXCOMEXLib.FaxServer();
var faxDoc = new FAXCOMEXLib.FaxDocument();
faxServer.Connect("");
faxDoc.Body = #"C:\\test.txt";
faxDoc.Recipients.Add("5551212", "Recipient");
faxDoc.ConnectedSubmit(faxServer);
}
is supposed to work, but it fails whenever I try to send a fax and I'm not sure why. Any ideas?
You are using both a literal qualifier and an escape character. You should just use one or the other.
You should try one of the following.
faxDoc.Body = #"C:\test.txt";
or
faxDoc.Body = "C:\\test.txt";
Related
I'm trying to create an application where I have to use WHOIS to get some information I need.
To get the WHOIS information I use this function I found on here and adjusted a little:
string Whois(string domain, string whoisServer = "whois.iana.org")
{
string toReturn = "";
TcpClient tcpClinetWhois = new TcpClient(whoisServer, 43);
MemoryStream memoryStreamWhois = new MemoryStream();
Task copying = tcpClinetWhois.GetStream().CopyToAsync(memoryStreamWhois);
StreamWriter streamWriter = new StreamWriter(tcpClinetWhois.GetStream());
streamWriter.WriteLine(domain);
streamWriter.Flush();
copying.Wait(3000);
toReturn = Encoding.ASCII.GetString(memoryStreamWhois.ToArray());
if (toReturn.Contains("refer:"))
{
toReturn = Whois(domain, toReturn.Split('\n').Where(W => W.StartsWith("refer:")).Select(R => R.Replace("refer:", "").Trim()).First());
}
return toReturn;
}
When I run it, it works for most TLDs like .com or .org but not for .co.uk or .network and probably others too. I have no idea why it wouldn't work because the right WHOIS server gets selected for the TLD. I am also not getting any errors.
I'm using .Net7.0 and my Android 11 phone for testing.
I've tested this exact same function with the exact same domains on the same network but in a Console Application with no problems at all! Everything works fine except when I try this function in a Xamarin Application.
I'm an Amazon FBA seller and I would like to begin to upload data regarding my sales in a more automated process using Amazon MWS. I just made an amazon MWS account and received my different IDs (Access Key Id, secret Access Key, ...).
I have the impression that most MWS developers use C#. I have a lot of Excel VBA experience but not in C#. Therefore, I'm not sure of the steps I have to follow.
On the webpage below, you can find a C# code that I would like to run:
http://www.samswiches.com/2011/02/how-to-use-amazon-mws-to-download-unshipped-order-reports/
Could you confirm the steps below are correct? :
1) Download Visual Studio => Do I need to download any extra package from Amazon?
2) In Visual Studio: File => New Project => C# console application
3) Erase all code and replace it by a copy-paste of the code found on above website => Do I need to put the code Inside something like "Sub - end Sub" in VBA?
4) Change "YourSecretKey", "YourSecretAccessKey", "YourSecretAccessKey", "YourMerchantID", "YourMarketplaceID" by my IDs.
5) Hit the run button
If it works, what will be the output like: An array inside Visual studio? A text file? A csv file? Where will it be stored?
I realize this is a very newbie question. However, I think that once I have a first code running correctly, my VBA experience will allow me to start efficiently from there.
Thanks in advance,
Diego.
After looking the code from http://www.samswiches.com/2011/02/how-to-use-amazon-mws-to-download-unshipped-order-reports/
I tried and changed something, and it works. Here is my solution:
Download the C# MWS Reports API Client Library: https://developer.amazonservices.com/doc/bde/reports/v20090101/cSharp.html
Use Visual Studio to create a project to get reports using MWS Reports API Client Library
Here is the code.
using System;
using System.Xml.Serialization;
using System.Collections.Generic;
using MarketplaceWebService;
using MarketplaceWebService.Mock;
using MarketplaceWebService.Model;
using System.IO;
using System.Threading;
public void testReport()
{
String accessKeyId = "Your Access Key ID";
String secretAccessKey = "Your Secret Access Key";
const string merchantId = "Merchant ID";
const string marketplaceId = "Marketplace ID";
MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();
config.ServiceURL = "https://mws.amazonservices.com";
const string applicationName = "ApplicationName";
const string applicationVersion = "0.01";
MarketplaceWebServiceClient service =
new MarketplaceWebServiceClient(
accessKeyId,
secretAccessKey,
applicationName,
applicationVersion,
config);
RequestReportRequest reportRequestRequest = new RequestReportRequest();
reportRequestRequest.Merchant = merchantId;
// you can change ReportType here:
//http://docs.developer.amazonservices.com/en_IN/reports/Reports_ReportType.html
reportRequestRequest.ReportType = “_GET_FLAT_FILE_ACTIONABLE_ORDER_DATA_";
RequestReportResponse requestResponse = service.RequestReport(reportRequestRequest);
IdList lstRequestID = new IdList();
lstRequestID.Id.Add
(requestResponse.RequestReportResult.ReportRequestInfo.ReportRequestId);
GetReportRequestListRequest reportRequestListRequest = new
GetReportRequestListRequest();
reportRequestListRequest.Merchant = merchantId;
reportRequestListRequest.ReportRequestIdList = lstRequestID;
List<ReportRequestInfo> myListzz = new List<ReportRequestInfo>();
GetReportRequestListResponse reportRequestListResponse = new
GetReportRequestListResponse();
reportRequestListResponse =
service.GetReportRequestList(reportRequestListRequest);
GetReportRequestListResult reportRequestListResult = new
GetReportRequestListResult();
reportRequestListResult =
reportRequestListResponse.GetReportRequestListResult;
myListzz = reportRequestListResult.ReportRequestInfo;
if (myListzz.Count > 0)
{
while (myListzz[0].ReportProcessingStatus.ToString() != "_DONE_")
{
Console.WriteLine("Waiting for Report");
Thread.Sleep(61000);
reportRequestListResponse =
service.GetReportRequestList(reportRequestListRequest);
reportRequestListResult =
reportRequestListResponse.GetReportRequestListResult;
myListzz = reportRequestListResult.ReportRequestInfo;
}
if (myListzz[0].GeneratedReportId !=null)
{
GetReportRequest reportRequest = new GetReportRequest();
reportRequest.Merchant = merchantId;
String source = "C:\\myreport.txt";
reportRequest.ReportId = myListzz[0].GeneratedReportId;
reportRequest.Report = File.Open(source, FileMode.Create,
FileAccess.ReadWrite);
service.GetReport(reportRequest);
}
}
}
You are missing step 1b) Download the C# MWS Reports API Client Library. You may need other libraries to access other parts of the MWS API, but from a quick glance at that code above library is the main one.
Note that it refers to a lblStatus, which seems to be a label on a form, but nowhere in that post does it say anything else about that form. So step 2) probably is not a "console" style application, but a form based one, which also means, you shouldn't erase all code in step 3, but paste the code into whatever is the equivalent of a main() function (I've only ever used C and C++, but not C#, so I have no clue)
My company has purchased the CoolUtils TotalPDFPrinterX from https://www.coolutils.com/TotalPDFPrinterX
I make an HTTP PUT from Postman to the API and I get “Could not get any response”.
When running on my Windows machine the PDF prints fine however on the server the site crashes and in the event log I get the error "A process serving application pool '[MY_APP_POOL]' failed to respond to a ping. The process id was '[MY_PROCESS_ID]'."
Here is my C# code:
PDFPrinterX ppx = new PDFPrinterX();
ppx.Print(fileName, printerName, "-ap Default");
if (ppx.ErrorMessage != null)
{
WriteToSQL(id, false, ppx.ErrorMessage, 2);
Console.WriteLine(ppx.ErrorMessage);
}
By writing to the event log I know the site crashes on this line: PDFPrinterX ppx = new PDFPrinterX(); I have also surrounded the above code with a try catch and no exception is thrown. The site still crashes.
Things I have tried:
Uninstalling and Reinstalling the CoolUtils software
Giving EVERYONE Full control to the site folder and the CoolUtils program folder
Creating a C# desktop application using the same code. THIS WORKS FINE ON THE SERVER. It's just the ASP site that crashes.
Does anyone know what might be causing this?
The more I research this thing online the more I'm inclined to say that ActiveX which is the X in PDFPrinterX doesn't seem to work well when hosted in IIS.
I've seen a few forums where they say it works fine when they debug on localhost but when deployed to server is crashes.
...works fine when used inside localhost(Visual studio)
One of their feature pages shows that it requires Win 2000/NT/XP/2003/Vista/7
You should look into whether your server supports ActiveX components that can work in conjunction with IIS.
Looking at one of their other products support page: TotalPDFConverterX:
the following note in my opinion may also apply to TotalPDFPrinterX, given its dependency on ActiveX as well.
Note: Pay attention to some details during installation Total PDF Converter X:
Do not forget to register ActiveX in your web-server account.
Total PDF Converter X supports only Internet Explorer, Mozilla and Firefox browsers.
ActiveX works only with 32-bit internet information server. 64-bit server is not supported. Use command line version instead.
Thanks to #Nkosi I was able to find a workaround.
ActiveX works only with 32-bit internet information server. 64-bit server is not supported. Use command line version instead.
Our IIS server is 64 bit so that is what probably caused the site to hang up.
Buttt... the command line still worked in printing the PDFs on the server.
Client side code (makes the HTTP POST):
private void SendToPrinter(string fileName, string printerName, int id, decimal documentSequence)
{
// use http client to make a POST to the print api
using (var client = new HttpClient())
{
// compile the values string to transfer in POST
// should finish to look something like this:
// C:\print.pdf&PRTFTW_OFIT&ValShip-155320-1
var values = new Dictionary<string, string>
{
{ "", fileName + "&" + printerName + "&ValShip-" + id + "-" + documentSequence},
};
// URL encode the values string
var content = new FormUrlEncodedContent(values);
// make the POST
// DEBUG
var response = client.PostAsync("http://localhost:54339/api/print", content);
// retrieve the response
var responseString = response.Result.ToString();
}
}
Server side code (receives the HTTP POST):
using System;
using System.Net.Http;
using System.Web;
using System.Web.Http;
namespace api.valbruna.print.Controllers
{
public class PrintController : ApiController
{
// POST api/print
public HttpResponseMessage Post(HttpRequestMessage request)
{
try
{
// parse the content recieved from the client
var content = request.Content.ReadAsStringAsync().Result;
// decode the content, certain characters such as
// '&' get encoded to URL lingo such as '%26'
content = HttpUtility.UrlDecode(content);
// split the string into 3 seperate parts
String[] str = content.Split('&');
// remove the equal sign from the first string
str[0] = str[0].Trim('=');
// compile the arguments command line string
// should finish to look something like this:
// "C:\Program Files (x86)\CoolUtils\Total PDF PrinterX\PDFPrinterX.exe" "C:\print.pdf" -p"\\PRINTERS\PRTFTW_OFIT" -ap Default -log "C:\inetpub\logs\CoolUtils\log-ValShip-155320-4.txt" -verbosity detail"
String arguments = "\"" + str[0] + "\" -p\"\\\\PRINTERS\\" + str[1] +
"\" -ap Default -log \"C:\\inetpub\\logs\\CoolUtils\\log-" + str[2] +
".txt\" -verbosity detail";
// file location for PDFPrinterX.exe
String file = #"C:\Program Files (x86)\CoolUtils\Total PDF PrinterX\PDFPrinterX.exe";
// start the process
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
startInfo.FileName = file;
startInfo.Arguments = arguments;
process.StartInfo = startInfo;
process.Start();
return new HttpResponseMessage() { Content = new StringContent(content) };
}
catch (Exception e)
{
return new HttpResponseMessage() { Content = new StringContent(e.Message) };
}
}
}
}
I need to create a qrreader with windows phone.
Xzing examples only print to video the qr string captured,
I need an example of how to understand if this string is a vcard and, consequently, save it in contact, or if it is a link and open it in the browser.
private void ScanPreviewBuffer()
{
try
{
_photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY);
var binarizer = new HybridBinarizer(_luminance);
var binBitmap = new BinaryBitmap(binarizer);
var result = _reader.decode(binBitmap);
Dispatcher.BeginInvoke(() => CheckQr(result.Text));
}
catch { }
}
private void CheckQr(string qrString)
{
VibrateController vibrate = VibrateController.Default;
vibrate.Start(TimeSpan.FromMilliseconds(500));
MessageBox.Show(qrString);
/* CONTROLS HERE */
}
Obviously you have to start by parsing the qrString content to get what you want, i think we'll both agree on that point ;)
So the main issues are :
Determining formats (url or vcard)
Parsing them (if needed)
Using them to trigger wanted actions
1. About vCard
To determine if you qrString holds a vCard, maybe you could just try to match (with string.Contains or string.StartsWith methods) the vCard header which is BEGIN:VCARD and always seems to be the same from one version to another (see wikipedia).
For Windows Phone 7, there's no builtin features to parse vCards, so you have to do it by yourself or you could try to use the vCard library For Windows Phone. It would be used this way :
byte[] byteArray = Encoding.UTF8.GetBytes(qrString);
using (StreamReader reader = new StreamReader(new MemoryStream(byteArray)))
{
vCard card = new vCard(reader);
// access here card.PropertyFromvCard to get the information you need
}
There's not so much documentation about it, but sources are available on codeplex, so you'll probably find all the property names and samples you need.
For Windows Phone 8, the builtin ContactInformation.ParseVcardAsync method could help you to parse your qrString content (here is an official tutorial)
Then you need to finally create your contact :
If you're developping your App on Windows Phone 7, there's no way to create a contact directly from your application. You need to use the "save contact task" and pre-populate the fields you need. Here's an example :
SaveContactTask saveContactTask = new SaveContactTask();
saveContactTask.Completed += new EventHandler<SaveContactResult>(saveContactTask_Completed);
saveContactTask.FirstName = "John"; // card.PropertyFromvCard and so on...
saveContactTask.LastName = "Doe";
saveContactTask.MobilePhone = "2065550123";
saveContactTask.Show();
If you're developping on Windows Phone 8 (and it doesn't seem to be the case given your question tags), you can create a Custom contact store and write directly into it
2. About URLs
To know if you're dealing with an URL or not, i would advice you to follow suggestions coming with this SO answer. To make a long story short, here's the code you could use or at least something similar :
static bool IsValidUrl(string qrString)
{
Uri uri;
return Uri.TryCreate(urlString, UriKind.Absolute, out uri)
&& (uri.Scheme == Uri.UriSchemeHttp
|| uri.Scheme == Uri.UriSchemeHttps
|| uri.Scheme == Uri.UriSchemeFtp
|| uri.Scheme == Uri.UriSchemeMailto
/*...*/);
}
And finally to open your URL into a web browser (if it is a valid one of course), you could use the WebBrowser task or embed a true WebBrowser into your application with the WebBrowser control and make good use of it.
ZXing has a class called ResultParser with a static method parseResult.
The ResultParser supports some common content formats like vCard, vEvent, URL, etc.
It gives you as a result an instance of AddressBookParsedResult for vCard content back.
ParsedResult parsedResult = ResultParser.parseResult(result);
I am making an application to make connection through SSH with my server using Routrek Granados library in C#.
I have done almost every thing. but not getting the way that how to receive response/data from the server.
does anyone knows?
please tell me, i shall be very thankful to you.
sample piece of code is here
var param=new SSHConnectionParameter();
param.UserName = "username";
param.Password = "password";
param.Protocol=SSHProtocol.SSH2;
param.AuthenticationType=AuthenticationType.Password;
param.PreferableCipherAlgorithms=new CipherAlgorithm[]{CipherAlgorithm.Blowfish, CipherAlgorithm.TripleDES, CipherAlgorithm.AES128, };
param.WindowSize = 0x1000;
var reader = new Reader();
var sock=new Socket(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp);
sock.Connect(new IPEndPoint(IPAddress.Parse("ip address"),(port number)));
_conn = SSHConnection.Connect(param, reader, sock);
reader._conn = _conn;
SSHChannel ch = _conn.OpenShell(reader);
reader._pf = ch;
SSHConnectionInfo info = _conn.ConnectionInfo;
In your reader class on method OnData the response that comes back you need to set to a public property and then at the end of your code up there check reader.new property. Note that this is all asynchronous so you may need to wait I recommend a waitsignal. I have complete code if needed.