I need some help on calling foxprogram from c# code.
We have dedicated machine where we have fox releated program.
Machine Name : TestFox
We have shared folder \\TestFox\FoxPrograms
I need to call init.prg which is present in \\TestFox\FoxPrograms [It is built in vfp9]
I used the below code
try
{
string foxCommand = "init.prg";
var parse = new FoxApplication();
parse.DefaultFilePath = #"\\TestFox\FoxPrograms";
parse.DoCmd(foxCommand);
}
catch (Exception ex)
{
//I m getting exception
//{System.Runtime.InteropServices.COMException (0x80020009):
//Exception occurred. (Exception from HRESULT:
//0x80020009 (DISP_E_EXCEPTION)) at VisualFoxpro.Application.DoCmd
//(String bstrCmd)
//at CallFox.Program.CallFoxPraser(String step)
//in C :\Users\ssnagendrakumar\documents\
//visual studio 2010\Projects\CallFox\CallFox\Program.cs:line 32}
}
I refered vfp9.exe in solution to get FoxApplication()
Can someone help me? please
I believe you need to use the VisualFoxpro.FoxApplication class, and you are passing invalid syntax - to execute a VFP program you need to use the DO command:
var parse = new VisualFoxpro.FoxApplication;
string foxCommand = "do init.prg";
parse.DefaultFilePath = #"\\TestFox\FoxPrograms";
parse.DoCmd(foxCommand);
Related
When I run this code:
var stream = File.OpenRead(#"C:\tmp\PdfToTest.PDF");
var latestVersion = GhostscriptVersionInfo.GetLastInstalledVersion();
rasterizer = new GhostscriptRasterizer();
rasterizer.Open(stream, latestVersion, false);
I am getting this error
An exception of type 'Ghostscript.NET.GhostscriptAPICallException' occurred in Ghostscript.NET.dll but was not handled in user code
Additional information: An error occured when call to 'gsapi_init_with_args' is made: -15
The error is in this line:
rasterizer.Open(stream, latestVersion, false);
Anyone could point me what it is causing this to happen?
I am running this in local machine. Installed the Ghostscript on Package manager console. Everything seems to be right, but it simple doesn't work.
-15 is a 'rangecheck' error. There should be considerable extra backchannel information which might give some useful details. However since you are not using Ghostscript directly I can't tell you where it might be going.
You should put the PDF file you are using as input somewhere public at least so we can look at it.
Ideally you should reproduce the problem with Ghostscript itself, from the command line, but in any event you must supply the configuration information (ie what settings you have used). The version of Ghostscript (and whether its 32 or 64 bit) would also be useful information.
I'm afraid there's nothing much anyone can do with what you've given us to go on.
This is my working example.
So I call the method ResizePDF(string filePath) and give the file path including extension (eg. C:\tmp\file.pdf) as parameter.
The method returns the memoryStream with the resized file that I can use to do whatever.
There are some work to do around it, however it is working so far.
internal MemoryStream ResizePDF(string filePath)
{
string inputFilePath = String.Format(#"{0}", filePath);
GhostscriptPipedOutput gsPipedOutput = new GhostscriptPipedOutput();
string outputPipeHandle = "%handle%" + int.Parse(gsPipedOutput.ClientHandle).ToString("X2");
MemoryStream memStream = null;
using (GhostscriptProcessor processor = new GhostscriptProcessor())
{
try
{
processor.Process(GetGsArgs(inputFile, outputPipeHandle));
byte[] rawDocumentData = gsPipedOutput.Data;
memStream = new MemoryStream(rawDocumentData);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
gsPipedOutput.Dispose();
gsPipedOutput = null;
}
}
return memStream;
}
private string[] GetGsArgs(string inputFilePath, string outputFilePath)
{
List<string> switches = new List<string>();
switches.Add("-empty");
switches.Add("-dQUIET");
switches.Add("-dSAFER");
switches.Add("-dBATCH");
switches.Add("-dNOPAUSE");
switches.Add("-dNOPROMPT");
switches.Add("-dPDFSETTINGS=/ebook");
switches.Add("-sDEVICE=pdfwrite");
switches.Add("-sPAPERSIZE=a4");
switches.Add("-sOutputFile=" + outputPipeHandle);
switches.Add("-f");
switches.Add(inputFilePath);
return switches.ToArray();
}
Thanks you all.
Here i am trying to read the local system event log using c# using this code-
string eventLogText = "";
try
{
var eventLog = new EventLog("logname", "machinename");
foreach (var entry in eventLog.Entries)
{
eventLogText += entry;
}
}
catch (Exception eg)
{
MessageBox.Show(eg.Message);
}
It is working well, but the problem is, in the variable eventLogText i get only System.Diagnostics.EventLogEntry repeatedly, may be this is very common mistake but i don't know what to do as i am very new to the c# as well as programming too.
Secondly i want to know that if a system is not logged in using Administrator account, in that case reading event log will cause any exception or error and if it will what will be the solution for it ?
Need help.Thanks in advance.
Regarding your first question, you are just adding the variable entry to the string, which is calling the ToString method on that variable. The default implementation of ToString is to return the name of the class. (Hence the repeated System.Diagnostics.EventLogEntryoutput)
You will need to use the members in the EventLogEntry class to retrieve the data you are interested in. For example, this console application will print the source and message of the first 10 entries in the Application event log:
static void Main(string[] args)
{
StringBuilder eventLogText = new StringBuilder();
try
{
var eventLog = new EventLog("Application");
var tenMostRecentEvents = eventLog.Entries
.Cast<EventLogEntry>()
.Reverse()
.Take(10);
foreach (EventLogEntry entry in tenMostRecentEvents)
{
eventLogText.AppendLine(String.Format("{0} - {1}: {2}",
entry.Source,
entry.TimeWritten,
entry.Message));
}
Console.WriteLine(eventLogText.ToString());
}
catch (System.Security.SecurityException ex)
{
Console.WriteLine(ex);
}
Console.ReadLine();
}
Regarding your second question, your code will need the appropriate permissions to read that event log. For example, if I change the code read the Security event log using this line var eventLog = new EventLog("Security"); I will receive a security exception. You can check this answer for more information
Hope it helps!
I am using WATIN 2.1 with C#. Here is my Code
// Should I add something here like []
private void ProcessInkPresenter()
{
String path = "http://localhost/index.asp?HOSTID=AD&USERID=&ALIAS=" + userName;
Int32 startingRow = 1;
using (var browser = new IE(path))
{
browser.AutoClose = true;
try
{
try
{
browser.Image(Find.ByAlt("Use a password")).Click();
browser.WaitForComplete(90);
browser.TextField(Find.ByName("_MYPW")).TypeText(privateCurrentPassword);
// the application keeps crashing in the line above
// WatiN.Core.Exceptions.RunScriptException : RunScript failed
// ----> System.UnauthorizedAccessException : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
browser.Image(Find.ByAlt("Verify password")).Click();
browser.Link(Find.ByTitle("Change passwords")).Click();
browser.TextField(Find.ByName("_NEWP1")).TypeText(privateNewPassword);
browser.TextField(Find.ByName("_NEWP2")).TypeText(privateNewPassword);
browser.Image(Find.ByName("SUBMIT-CHANGE")).Click();
I basically need to get this to work with Internet Explorer 7 and up on Windows XP.
Can you please help me with this?
I added the CRASH details in the code above
Thanks
Is the field found?
var field = browser.TextField(Find.ByName("_MYPW"));
if(field.Exists)
field.TypeText(privateCurrentPassword);
I had a similar issue trying to get an HTML5 input type email.
It could also be other reasons watin can't get to the field.
How can I save an Access report in .net to the user's pc? I've tried using Access.SaveAsAXL, Docmd.OutputTo, and few other ways, but to no avail. The following is my latest attempt.
string dbname = "D:\\filename.mdb";
Microsoft.Office.Interop.Access.Application oAccess = new Microsoft.Office.Interop.Access.Application();
oAccess.OpenCurrentDatabase(dbname, true);
oAccess.Visible = true;
var acFormatXLS = "Microsoft Excel (*.xls)";
string id = "tblJobs.JobID=" + (Convert.ToInt32(GetMaxJobID())).ToString();
try
{
oAccess.Run("BuildXAxisTimeLine", Convert.ToInt32(GetMaxJobID()));
oAccess.SaveAsAXL(Microsoft.Office.Interop.Access.AcObjectType.acReport, "rptChartData", "D:\\report.xls");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
//oAccess.CloseCurrentDatabase();
}
The error i receive is:
hresult e_fail has been returned from a call to a com component
any help would be greatly appreciated. Thank you.
The followig code solved my problem. place this in the try section as shown above instead of oAccess.SaveAsAxl line of code and right under the .Run line of code.
oAccess.DoCmd.OpenReport("rptChartData", Microsoft.Office.Interop.Access.AcView.acViewPreview, null,id);
oAccess.DoCmd.OutputTo(Microsoft.Office.Interop.Access.AcOutputObjectType.acOutputReport, "rptChartData", acFormatXLS, "D:\\reportname.pdf",false, null, null);
var speechEngine = new SpVoiceClass();
SetVoice(speechEngine, job.Voice);
var fileMode = SpeechStreamFileMode.SSFMCreateForWrite;
var fileStream = new SpFileStream();
try
{
fileStream.Open(filePath, fileMode, false);
speechEngine.AudioOutputStream = fileStream;
speechEngine.Speak(job.Script, SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak | SpeechVoiceSpeakFlags.SVSFDefault); //TODO: Change to XML
//Wait for 15 minutes only
speechEngine.WaitUntilDone((uint)new TimeSpan(0, 15, 0).TotalMilliseconds);
}
finally
{
fileStream.Close();
}
This exact code works in a WinForm app, but when I run it inside a webservice I get the following
System.Runtime.InteropServices.COMException was unhandled
Message="Exception from HRESULT: 0x80045003"
Source="Interop.SpeechLib"
ErrorCode=-2147201021
Does anyone have any ideas what might be causing this error? The error code means
SPERR_UNSUPPORTED_FORMAT
For completeness here is the SetVoice method
void SetVoice(SpVoiceClass speechEngine, string voiceName)
{
var voices = speechEngine.GetVoices(null, null);
for (int index = 0; index < voices.Count; index++)
{
var currentToken = (SpObjectToken)voices.Item(index);
if (currentToken.GetDescription(0) == voiceName)
{
speechEngine.SetVoice((ISpObjectToken)currentToken);
return;
}
}
throw new Exception("Voice not found: " + voiceName);
}
I have given full access to USERS on the folder C:\Temp where the file is to be written. Any help would be appreciated!
I don't think the System.Speech works in windows service. It looks like there is a dependency to Shell, which isn't available to services. Try interop with SAPI's C++ interfaces. Some class in System.Runtime.InteropServices may help on that.
Our naming convention requires us to use a non-standard file extension. This works fine in a Winforms app, but failed on our web server. Changing the file extension back to .wav solved this error for us.
Make sure you explicitly set the format on the SPFileStream object. ISpAudio::SetState (which gets called in a lower layer from speechEngine.Speak) will return SPERR_UNSUPPORTED_FORMAT if the format isn't supported.
I just got the webservice to spawn a console app to do the processing. PITA :-)