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);
Related
I am creating an import / export tool for CRM using C#.
Sometimes, I am facing to an import error, with only this message "Solution manifest import: FAILURE" in my catch. I tried to cast it to its type (FaultException), but I haven't any more details.
If I do the import of the same file directly in CRM, I have a better error message (this one for exemple : "Import of solution xxxx failed. The following components are missing in yout system [...]").
Is there a way to get this complete message ?
Here is my code :
try
{
_serviceProxy.Execute(impSolReq);
}
catch (Exception ex)
{
if (ex is FaultException<OrganizationServiceFault>)
MessageBox.Show("Error during import. More details: " + ((FaultException<OrganizationServiceFault>)ex).Detail);
else
MessageBox.Show("Error during import. More details: " + ex.Message);
}
Thanks for your answers !
Dynamics CRM solutions are imported using the ImportSolutionRequest.
The ImportSolutionRequest has a property containing the ID of the solution import job. You need this ID to be able to monitor the progress of the job and to get error details when the import fails.
Instantiation of the request could look like this:
Guid importJobId = Guid.NewGuid();
var request = new ImportSolutionRequest
{
ConvertToManaged = true,
CustomizationFile = buffer, // a byte[] array holding the solution contents
ImportJobId = importJobId,
OverwriteUnmanagedCustomizations = true,
PublishWorkflows = true,
SkipProductUpdateDependencies = false
};
Execute the request. When an import error occurs, you can retrieve the error details using the job id.
try
{
_service.Execute(request);
}
catch (FaultException<OrganizationServiceFault> ex)
{
if (ex.Detail.ErrorCode == -2147188685) // ImportSolutionError
{
Entity job = _service.Retrieve("importjob", importJobId, new ColumnSet { AllColumns = true });
// TODO: process job error details.
}
throw;
}
Attribute importjob.data contains an XML document with the details you are looking for.
The ImportSolutionRequest is executed synchronously and can easily time-out. Time-outs however can safely be ignored, because the import process continues to run in the background. You can track progress by retrieving the import job record at regular intervals. As long as attribute importjob.completedon is null, the job is still running.
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.
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);
I have a app that should create a excel spreadsheet and save it. The app works runs without any problems on other machines, including my bosses computer(he has the same ver of office and VS as me). I don't know if this is relevant but I have office 2013 and VS 2012.
Edit I'm trying to save as a .xls (exel 97').
SNIPIT
public static bool XLSaveAs(ref Excel._Workbook oWBTemplate, string FileName)
{
System.IO.FileInfo x = new System.IO.FileInfo(FileName);
if (x.Exists)
{
try
{
x.Delete();
}
catch
{
MyControls.MsgFunctions.WarningMsg("Make sure " + FileName + " is not open.");
return false;
}
}
try
{
if(FileName.Contains(".xlsx"))
oWBTemplate.SaveAs(FileName);
else
//Error occurs here
oWBTemplate.SaveAs(FileName, Excel.XlFileFormat.xlExcel8);
}
catch
{
MyControls.MsgFunctions.WarningMsg("Unable to save " + FileName);
return false;
}
return true;
}
If I take out the try catch statement this is the error I get.
ERROR
COMException as unhandled
Exception from HRESULT: 0x800A03EC
I found a solution that worked for me.
I had incorrect permissions to edit the folder that excel was writing too.
Adding full control to the folder resolved the issue.
Also the command oWBTemplate.SaveAsCopy() could help if you have a similar issue.
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.