I am using FastReport in ASP.net MVC. I wrote some code for removing the report title when exporting to Excel. It works properly. But sometimes the report is shown and after that export method is called; in this case when I push the Next Page button in FastReport's toolbar, I see that the report title was removed. I wrote this:
FastReport.Utils.Config.WebMode = true;
ExportBase export = null;
var webReportExport = new WebReport();
//keep werreport object in tempdata in first loading of report for using it to export later
webReportExport.Report = TempData["WebReport"] as FastReport.Report;
webReportExport.Report.FindObject("PageHeader1").Delete();
webReportExport.Report.FindObject("PageFooter1").Delete();
TempData.Keep("WebReport");
ViewBag.WebReport = TempData["WebReport"] as FastReport.Report;
if (webReportExport.Report.Prepare())
{
switch (exportType)
{
case "pdf": export = new FastReport.Export.Pdf.PDFExport(); break;
case "excel": export = new FastReport.Export.OoXML.Excel2007Export() ; break;
case "word": export = new FastReport.Export.OoXML.Word2007Export(); break;
case "rtf": export = new FastReport.Export.RichText.RTFExport(); break;
default:
break;
}
export.ShowProgress = false;
MemoryStream strm = new MemoryStream();
webReportExport.Report.Export(export, strm);
webReportExport.Dispose();
export.Dispose();
strm.Position = 0;
var currentDate = PersianDate.Parse(PersianDateConverter.ToPersianDate(DateTime.Now).ToString()).ToString("swt");
var reportName = TempData["reportName"] + currentDate;
switch (exportType)
{
case "pdf": return File(strm, "application/pdf", reportName+".pdf"); break;
case "excel": return File(strm, "application/ms-excel", reportName+".xlsx"); break;
case "word": return File(strm, "application/vnd.openxmlformats-officedocument.wordprocessingml.document",reportName+ ".docx"); break;
case "rtf": return File(strm, "application/rtf", reportName+".rtf"); break;
default:
break;
}
}
return null;
Related
This api controller is used to return a pdf stream to display in an html object tag
using AspNetCore.Reporting;
using Microsoft.AspNetCore.Mvc;
[HttpGet, Route("ProcedureRangeForm")]
public IActionResult ProcedureRangeForm(string procedureRangeId, byte procedureTypeId)
{
int extension = 1;
var _reportPath = "";
switch (procedureRangeId)
{
case "1":
_reportPath = #"Reports\ProcedureRangeForm1.rdlc";
break;
case "2":
_reportPath = #"Reports\ProcedureRangeForm2.rdlc";
break;
case "3":
_reportPath = #"Reports\ProcedureRangeForm3.rdlc";
break;
default:
// code block
break;
}
//Employee employee = _context.Employees.FirstOrDefault(x => x.Id == "41")!;
ProcedureType procedureType = _context.ProcedureTypes.FirstOrDefault(x => x.Id == procedureTypeId);
//RelationDegree relationDegree = _context.RelationDegrees.FirstOrDefault(x => x.Id == 1)!;
var reportParams1 = new Dictionary<string, string>();
var reportParams2 = new Dictionary<string, string>();
var reportParams3 = new Dictionary<string, string>();
reportParams1.Add("UnitCode", "UnitCode");
reportParams1.Add("ProcedureType", procedureType!.Name!);
reportParams2.Add("ProcedureType", procedureType!.Name!);
reportParams3.Add("ProcedureType", procedureType!.Name!);
//reportParams1.Add("Attachments", "");
LocalReport localReport = new LocalReport(_reportPath);
FileContentResult fileContentResult;
MemoryStream memory = new();
try
{
ReportResult result = null!;
switch (procedureRangeId)
{
case "1":
result = localReport.Execute(RenderType.Pdf, extension, parameters: reportParams1);
break;
case "2":
result = localReport.Execute(RenderType.Pdf, extension, parameters: reportParams2);
break;
case "3":
result = localReport.Execute(RenderType.Pdf, extension, parameters: reportParams3);
break;
default:
// code block
break;
}
byte[] file = result.MainStream;
fileContentResult = new FileContentResult(file, "application/pdf");
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
return Content(HttpStatusCode.InternalServerError.ToString(), e.Message);
}
finally
{
}
return fileContentResult;
}
I want to call this api more than once with varient parameters. when i call once to display ProcedureRangeForm1.rdlc it run successfully , but when i call again to display ProcedureRangeForm2.rdlc throw this exception
System.FormatException: 'The header contains invalid values at index 0: 'An error occurred during local report processing.;The definition of the report 'Reports\ProcedureRangeForm1.rdl' is invalid. An unexpected error occurred in Report Processing. The process cannot access the file 'hdsktzjh.err' because it is being used by another process.''
After a lot of research, I found a solution to my question:
First, I used nuget package Tmds.ExecFunction by Execute a function in a separate process
as in this link
But I didn't get what I wanted
And then I replaced the library AspNetCore.Reporting by ReportViewerCore.NETCore
as in this link
the problem solved as this code
using Microsoft.Reporting.NETCore;
[Route("api/[controller]")]
[ApiController]
public class ProcedureRangeFormsController : ControllerBase
{
private readonly HousingDbContext _context;
public ProcedureRangeFormsController(HousingDbContext context)
{
_context = context;
}
// GET api/values
[HttpGet, Route("ProcedureRangeForm/{procedureRangeId}/{procedureTypeId}")]
public IActionResult ProcedureRangeForm(string procedureRangeId, string procedureTypeId)
{
var reportPath = "";
switch (procedureRangeId)
{
case "1":
reportPath = "TaxHousing.Reports.ProcedureRangeForm1.rdlc";
break;
case "2":
reportPath = "TaxHousing.Reports.ProcedureRangeForm2.rdlc";
break;
case "3":
reportPath = "TaxHousing.Reports.ProcedureRangeForm3.rdlc";
break;
default:
// code block
break;
}
using var rs = Assembly.GetExecutingAssembly().GetManifestResourceStream(reportPath);
var localReport = new Microsoft.Reporting.NETCore.LocalReport();
localReport.LoadReportDefinition(rs);
var reportParams1 = new[] {
new ReportParameter("ProcedureType", "ProcedureType1"),
new ReportParameter("UnitCode", "UnitCode1")
};
var reportParams2 = new[] {
new ReportParameter("ProcedureType", "ProcedureType2")
};
var reportParams3 = new[] {
new ReportParameter("ProcedureType", "ProcedureType3")
};
byte[] file = null;
switch (procedureRangeId)
{
case "1":
localReport.SetParameters(reportParams1);
break;
case "2":
localReport.SetParameters(reportParams2);
break;
case "3":
localReport.SetParameters(reportParams3);
break;
default:
// code block
break;
}
try
{
file = localReport.Render("PDF");
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
return Content(HttpStatusCode.InternalServerError.ToString(), e.Message);
}
return new FileContentResult(file, "application/pdf");
}
}
In my application, I am using Windows.Devices.WiFi namespace to get the wifi network information. Here, I am using WiFiPhyKind property to get the 'radio type'. But in the UI, I have to display the Radio Type in the standard format (802.11a, 802.11ac, 802.11n ....).
Is there a way to convert it?
Sample code:
string radioType = "Unknown";
switch (wifiNetwork.PhyKind)
{
case WiFiPhyKind.Ofdm:
radioType = "?????";
break;
case WiFiPhyKind.Erp:
radioType = "?????";
break;
case WiFiPhyKind.HT:
radioType = "?????";
break;
case WiFiPhyKind.Vht:
radioType = "?????";
break;
case WiFiPhyKind.Unknown:
radioType = "?????";
break;
default:
radioType = "Unknown";
break;
}
The documentation for the enum seems to have some of the info
Dmg = 802.11ad
Erp = 802.11g
HE = 802.11ax
HT = 802.11n
Vht = 802.11ac
The 802.11 specifications could probably fill in the gaps
I'm implementing serverReport in a CRM workflow.(not online version)
I set the workflow non-sandbox and I'm trying to implement a version of ServerReport i'm using in a C# Webservice.
This is the code: (the last line is the one throwing the exception)
sr.ReportServerUrl = new Uri(reportServerBaseURL);
sr.ReportPath = reportDir + reportName;
// Credential to connect with CRM
IReportServerCredentials irsc = new CustomReportCredentials(username, password, "");
sr.ReportServerCredentials = irsc;
if (paramList != null && paramList.Count > 0)
{
bool isTimeout = true;
for (int i = 0; i < 6; i++)
{
try
{
sr.Timeout = 5000;
sr.Refresh();
sr.SetParameters(paramList);
isTimeout = false;
break;
}
catch (Exception ex)
{
}
}
if (isTimeout)
{
string message = "Report timeout";
throw new Exception(message);
}
}
sr.Timeout = 5000;
sr.Refresh();
string renderingString = null;
switch (renderingMethod)
{
case RSRenderingMethods.PDF:
renderingString = "PDF";
break;
case RSRenderingMethods.EXCEL:
renderingString = "EXCEL";
break;
case RSRenderingMethods.PNG:
case RSRenderingMethods.JPEG:
case RSRenderingMethods.GIF:
case RSRenderingMethods.TIFF:
renderingString = "IMAGE";
break;
}
//I'm reaching this point without problems, the format I'm using is PDF
byte[] bytes = bytes = sr.Render(renderingString, null); //this line is throwing the exception
With the WebService I had no problems for the report rendering, and I don't know why this time I'm having them.
The report is about 30-40 rows, so it's not big at all. Might the problem be in something I'm doing?
I need add to a edittext data previously loaded from stored procedure. But only add the first row of the column of name "Respuestas" the id of "Preguntas" is id cod_pregunta. But I need that the other "respuestas" too add to next edittext this is the code.
public void mostrarDatos(int posicion)
{
CotiBenev = tablaVerificacionAnexosV.Rows[posicion]["Usuario"].ToString();
Batchid = tablaVerificacionAnexosV.Rows[posicion]["iBatchId"].ToString();
primerApellido = tablaVerificacionAnexosV.Rows[posicion]["Primer apellido"].ToString();
segundoApellido = tablaVerificacionAnexosV.Rows[posicion]["Segundo apellido"].ToString();
primerNombre = tablaVerificacionAnexosV.Rows[posicion]["Primer Nombre"].ToString();
segundoNombre = tablaVerificacionAnexosV.Rows[posicion]["Segundo Nombre"].ToString();
cons_pregunta = tablaVerificacionAnexosV.Rows[posicion]["consecutivo pregunta"].ToString();
cod_pregunta = tablaVerificacionAnexosV.Rows[posicion]["Codigo pregunta"].ToString();
cod_aportante = tablaVerificacionAnexosV.Rows[posicion]["Codigo aportante"].ToString();
Respuesta = tablaVerificacionAnexosV.Rows[posicion]["Respuesta"].ToString();
rutaTapa = tablaVerificacionAnexosV.Rows[posicion]["Ruta Tapa"].ToString();
rutaAnexo = tablaVerificacionAnexosV.Rows[posicion]["Ruta Anexo"].ToString();
try
{
imagenTapa = new Bitmap(rutaTapa);
}
catch (Exception e)
{
botonSiguiente();
}
try
{
imagenAnexo = new Bitmap(rutaAnexo);
}
catch (Exception e)
{
botonSiguiente();
}
// textBoxCantidadRegistrosV.Text = cantidadRegistros;
//textBoxNumeroRegistroV.Text = (posicion + 1) + "";
textBoxCotiBene.Text = CotiBenev;
// activarCamposValidacionAnexos();
pictureBoxTapa.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBoxAnexo.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBoxTapa.Image = (Image)imagenTapa;
pictureBoxAnexo.Image = (Image)imagenAnexo;
// textBoxValorTapaV.Focus();
textBoxCotiBene.Text = CotiBenev + ": " + primerApellido + segundoApellido + primerNombre + segundoNombre;
string caseSwitch = cod_pregunta;
switch (caseSwitch)
{
case "1.1":
textBoxPreg_1_1.Text = Respuesta;
break;
case "1.2":
textBoxPreg_1_2.Text = Respuesta;
break;
case "1.3":
textBoxPreg_1_3.Text = Respuesta;
break;
case "1.4":
textBoxPreg_1_4.Text = Respuesta;
break;
case "1.5":
textBoxPreg_1_5.Text = Respuesta;
break;
case "1.6":
textBoxPreg_1_6.Text = Respuesta;
break;
case "1.7":
textBoxPreg_1_7.Text = Respuesta;
break;
case "1.8":
textBoxPreg_1_8.Text = Respuesta;
break;
case "2.1":
textBoxPreg_2_1.Text = Respuesta;
break;
case "2.2":
textBoxPreg_2_2.Text = Respuesta;
break;
case "2.3":
textBoxPreg_2_3.Text = Respuesta;
break;
case "2.4":
textBoxPreg_2_4.Text = Respuesta;
break;
case "2.5":
textBoxPreg_2_5.Text = Respuesta;
break;
case "2.6":
textBoxPreg_2_6.Text = Respuesta;
break;
case "2.7":
textBoxPreg_2_7.Text = Respuesta;
break;
case "2.8":
textBoxPreg_2_8.Text = Respuesta;
break;
case "2.9":
textBoxPreg_2_9.Text = Respuesta;
break;
case "2.10":
textBoxPreg_2_10.Text = Respuesta;
break;
case "2.11":
textBoxPreg_2_11.Text = Respuesta;
break;
case "2.12":
textBoxPreg_2_12.Text = Respuesta;
break;
case "2.13":
textBoxPreg_2_13.Text = Respuesta;
break;
case "2.14":
textBoxPreg_2_14.Text = Respuesta;
break;
case "2.15":
textBoxPreg_2_15.Text = Respuesta;
break;
case "2.16":
textBoxPreg_2_16.Text = Respuesta;
break;
case "2.17":
textBoxPreg_2_17.Text = Respuesta;
break;
case "2.18":
textBoxPreg_2_18.Text = Respuesta;
break;
case "2.19":
textBoxPreg_2_19.Text = Respuesta;
break;
case "2.20":
textBoxPreg_2_20.Text = Respuesta;
break;
case "3.1":
textBoxPreg_3_1.Text = Respuesta;
break;
case "3.2":
textBoxPreg_3_2.Text = Respuesta;
break;
case "3.3":
textBoxPreg_3_3.Text = Respuesta;
break;
case "3.4":
textBoxPreg_3_4.Text = Respuesta;
break;
case "3.5":
textBoxPreg_3_5.Text = Respuesta;
break;
case "4.1":
textBoxPreg_4.Text = Respuesta;
break;
default:
Console.WriteLine("No existe esa pregunta");
break;
}
}
I'm doing a voip client code with mumble in Unity3d (c# scripting) and now I'm able to successfully connect to any of mumble public server. But when I try to deserialize a UDP tunnel I get a lot of exceptions including 'invalid wiretype', 'number overflow', 'invalid field', 'endofstream', 'wrong group was ended' and bla bla... all of the at this particular line.
var udpTunnel = Serializer.DeserializeWithLengthPrefix<UDPTunnel> (_ssl, PrefixStyle.Fixed32BigEndian);
where _ssl is SslStream
Here is my complete method
nternal void ProcessTcpData ()
{
try {
var masg = IPAddress.NetworkToHostOrder (_reader.ReadInt16 ());
MessageType messageType = (MessageType)masg;
Debug.Log ("Received message type: " + messageType);
switch (messageType) {
case MessageType.Version:
_mc.RemoteVersion = Serializer.DeserializeWithLengthPrefix<Version> (_ssl,
PrefixStyle.Fixed32BigEndian);
break;
case MessageType.CryptSetup:
var cryptSetup = Serializer.DeserializeWithLengthPrefix<CryptSetup> (_ssl,
PrefixStyle.Fixed32BigEndian);
ProcessCryptSetup (cryptSetup);
break;
case MessageType.CodecVersion:
_mc.CodecVersion = Serializer.DeserializeWithLengthPrefix<CodecVersion> (_ssl,
PrefixStyle.Fixed32BigEndian);
break;
case MessageType.ChannelState:
_mc.ChannelState = Serializer.DeserializeWithLengthPrefix<ChannelState> (_ssl,
PrefixStyle.Fixed32BigEndian);
break;
case MessageType.PermissionQuery:
_mc.PermissionQuery = Serializer.DeserializeWithLengthPrefix<PermissionQuery> (_ssl,
PrefixStyle.Fixed32BigEndian);
break;
case MessageType.UserState:
_mc.UserState = Serializer.DeserializeWithLengthPrefix<UserState> (_ssl,
PrefixStyle.Fixed32BigEndian);
break;
case MessageType.ServerSync:
_mc.ServerSync = Serializer.DeserializeWithLengthPrefix<ServerSync> (_ssl,
PrefixStyle.Fixed32BigEndian);
_mc.ConnectionSetupFinished = true;
break;
case MessageType.ServerConfig:
_mc.ServerConfig = Serializer.DeserializeWithLengthPrefix<ServerConfig> (_ssl,
PrefixStyle.Fixed32BigEndian);
_validConnection = true; // handshake complete
break;
case MessageType.TextMessage:
var textMessage = Serializer.DeserializeWithLengthPrefix<TextMessage> (_ssl, PrefixStyle.Fixed32BigEndian);
break;
case MessageType.UDPTunnel:
if (_validConnection) {
var udpTunnel = Serializer.DeserializeWithLengthPrefix<UDPTunnel> (_ssl, PrefixStyle.Fixed32BigEndian);
}
break;
case MessageType.Ping:
var ping = Serializer.DeserializeWithLengthPrefix<MumbleProto.Ping> (_ssl, PrefixStyle.Fixed32BigEndian);
Debug.Log ("Received ping: " + ping.timestamp + ", udp: " + ping.udp_packets + ", tcp:" +
ping.tcp_packets);
break;
case MessageType.Reject:
var reject = Serializer.DeserializeWithLengthPrefix<Reject> (_ssl,
PrefixStyle.Fixed32BigEndian);
_validConnection = false;
_errorCallback ("Mumble server reject: " + reject.reason, true);
break;
default:
_errorCallback ("Message type " + messageType + " not implemented", true);
break;
}
if (_validConnection) {
Debug.Log ("Handshake Complete:\tconnection is valid");
}
} catch (Exception ex) {
Debug.LogException (ex);
}
}
_reader is a BinaryReader
I've got past this by using
var size = IPAddress.NetworkToHostOrder (_reader.ReadInt32 ());
var udpTunnel = new UDPTunnel { packet = _reader.ReadBytes(size) };
Now I don't know why Deserializewithlengthprefix was not working because as I understand, these lines are doing the same thing.