Last post Jun 17, 2014 03:08 PM by Rion Williams
Member
13 Points
53 Posts
Jun 17, 2014 02:32 PM|gymrat29|LINK
Hello,
I converted a VB.Net file to C# and I'm getting issues with one line of code (in bold) that the error states:
Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
Not sure what to use in the place of .Extension? Code is:
-----------------------------------------------------------------
public void PrintDocs(string basketId, string shopperId, string printerName) { try { _ixBase = new ImagXpress(); _printPro = new PrintPro(); _pdfRenderOpt = new Accusoft.PdfXpressSdk.RenderOptions { RenderAnnotations = true, ResolutionX = 300, ResolutionY = 300 }; _printer = Printer.SelectPrinter(_printPro, printerName); _pdfExpress = new Accusoft.PdfXpressSdk.PdfXpress(); _pdfExpress.Initialize(); dynamic dirInfo = new DirectoryInfo(ImgPath + basketId + "_" + shopperId); FileInfo[] fileInfo = dirInfo.GetFiles().Where(x => x.Extension == ".tif" | x.Extension == ".pdf").ToArray(); //Loop through each document foreach (var tmpFile in fileInfo) { var ext = tmpFile.Extension.ToLower(); var fileName = tmpFile.FullName; var pgCount = ImageX.NumPages(_ixBase, fileName); for (var i = 1; i <= pgCount; i++) { _printJob = new PrintJob(_printer); ImageX ixTemp; if (ext == ".tif") { ixTemp = ImageX.FromFile(_ixBase, fileName, i); } else { _pdfExpress.Documents.Add(fileName); var pdfBitmap = _pdfExpress.Documents[i - 1].RenderPageToBitmap(i - 1, _pdfRenderOpt); ixTemp = ImageX.FromBitmap(_ixBase, pdfBitmap); pdfBitmap.Dispose(); }
var dib = ixTemp.ToHdib(false); _printJob.PrintDib(dib, 0, 0, ixTemp.ImageXData.Width, ixTemp.ImageXData.Height, _printJob.LeftMargin, _printJob.TopMargin, _printJob.PrintWidth, _printJob.PrintHeight, true);
if (_pdfExpress.Documents.Count > 0) _pdfExpress.Documents.Clear(); _printJob.Finish(); ixTemp.Dispose(); _printJob.Dispose(); _printJob = null; } } _pdfExpress.Dispose(); _printer.Dispose(); _printPro.Dispose(); _ixBase.Dispose(); } catch (Exception ex) { if (_printJob != null) _printJob.Kill(); throw; } }
CodeBehind c asp.net #
All-Star
101931 Points
20703 Posts
Jun 17, 2014 02:50 PM|MetalAsp.Net|LINK
Use two | instead of just one. So x.blah == blah || x.blah2 == blah2
Edit: also use DirectoryInfo instead of dynamic to declare dirInfo.
114593 Points
18503 Posts
MVP
Jun 17, 2014 03:08 PM|Rion Williams|LINK
If you needed to check the extensions of each of your appropriate files, you could use the Path.GetExtension() method as seen below :
FileInfo[] files = YourDirectory.GetFiles().Where(x => Path.GetExtension(x) == ".tif" || Path.GetExtension(x) == ".pdf");
or using the String.EndsWith() method :
FileInfo[] files = YourDirectory.GetFiles().Where(x => x.EndsWith(".tif") || x.EndsWith(".pdf"));
Member
13 Points
53 Posts
Looking up file extension C#
Jun 17, 2014 02:32 PM|gymrat29|LINK
Hello,
I converted a VB.Net file to C# and I'm getting issues with one line of code (in bold) that the error states:
Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
Not sure what to use in the place of .Extension? Code is:
-----------------------------------------------------------------
public void PrintDocs(string basketId, string shopperId, string printerName)
{
try
{
_ixBase = new ImagXpress();
_printPro = new PrintPro();
_pdfRenderOpt = new Accusoft.PdfXpressSdk.RenderOptions
{
RenderAnnotations = true,
ResolutionX = 300,
ResolutionY = 300
};
_printer = Printer.SelectPrinter(_printPro, printerName);
_pdfExpress = new Accusoft.PdfXpressSdk.PdfXpress();
_pdfExpress.Initialize();
dynamic dirInfo = new DirectoryInfo(ImgPath + basketId + "_" + shopperId);
FileInfo[] fileInfo = dirInfo.GetFiles().Where(x => x.Extension == ".tif" | x.Extension == ".pdf").ToArray();
//Loop through each document
foreach (var tmpFile in fileInfo)
{
var ext = tmpFile.Extension.ToLower();
var fileName = tmpFile.FullName;
var pgCount = ImageX.NumPages(_ixBase, fileName);
for (var i = 1; i <= pgCount; i++)
{
_printJob = new PrintJob(_printer);
ImageX ixTemp;
if (ext == ".tif")
{
ixTemp = ImageX.FromFile(_ixBase, fileName, i);
}
else
{
_pdfExpress.Documents.Add(fileName);
var pdfBitmap = _pdfExpress.Documents[i - 1].RenderPageToBitmap(i - 1, _pdfRenderOpt);
ixTemp = ImageX.FromBitmap(_ixBase, pdfBitmap);
pdfBitmap.Dispose();
}
var dib = ixTemp.ToHdib(false);
_printJob.PrintDib(dib, 0, 0, ixTemp.ImageXData.Width, ixTemp.ImageXData.Height, _printJob.LeftMargin, _printJob.TopMargin, _printJob.PrintWidth, _printJob.PrintHeight, true);
if (_pdfExpress.Documents.Count > 0)
_pdfExpress.Documents.Clear();
_printJob.Finish();
ixTemp.Dispose();
_printJob.Dispose();
_printJob = null;
}
}
_pdfExpress.Dispose();
_printer.Dispose();
_printPro.Dispose();
_ixBase.Dispose();
}
catch (Exception ex)
{
if (_printJob != null)
_printJob.Kill();
throw;
}
}
CodeBehind c asp.net #
All-Star
101931 Points
20703 Posts
Re: Looking up file extension C#
Jun 17, 2014 02:50 PM|MetalAsp.Net|LINK
Use two | instead of just one. So x.blah == blah || x.blah2 == blah2
Edit: also use DirectoryInfo instead of dynamic to declare dirInfo.
CodeBehind c asp.net #
All-Star
114593 Points
18503 Posts
MVP
Re: Looking up file extension C#
Jun 17, 2014 03:08 PM|Rion Williams|LINK
If you needed to check the extensions of each of your appropriate files, you could use the Path.GetExtension() method as seen below :
or using the String.EndsWith() method :
CodeBehind c asp.net #