i have a big problem and i need your help. i'm trying send to url parameters to generate the pdf file with the library winnovative. when trying the first time I have no problems and generates pdf but if I want to get the pdf again this gives me error because the parameters in url they are sent and fail to request and falls when so finally assign to generate the pdf file.
I have attached the code for review:
public override void Pagina_PrimeraCarga(object sender, EventArgs e)
{
string datosRequest = Request.QueryString["DATOS"];
char delimitadores = ';';
string[] datos = datosRequest.Split(delimitadores);
imgBanco.Attributes.Add("ImageUrl", "~/App_Themes/Imagenes/Logo.gif");
System.DateTime fecha = new System.DateTime(2014, 12, 17);
lblDia.Text = Convert.ToString(fecha.Day);
lblMes.Text = Convert.ToString(fecha.Month);
lblAno.Text = Convert.ToString(fecha.Year);
string rutEmpresa = datos[3];
int rut = Convert.ToInt32(rutEmpresa);
string rutRes = rut.ToString("N0", CultureInfo.InvariantCulture).Replace(",", ".");
rutRes = rutRes + "-" + datos[4];
lblOficina.Text = "OFICINA: " + datos[0];
lblNombreTitular.Text = "NOMBRE TITULAR: " + datos[1];
lblRut.Text = "R.U.T.: " + rutRes;
lblDireccion.Text = "DIRECCION: " + datos[2];
lblFono.Text = "FONO: " + datos[5];
}
P.D: my apologies for my bad English but my native language is Spanish
P.D.2: Thanks to everyone who could help me in this case
I think that your problem is that after postBack your query string will be empty. Try this
add hiddenfield
<asp:HiddenField runat="server" ID="hidden1" />
then in your pageLoad
if (!IsPostBack)
{
string datosRequest = Request.QueryString["DATOS"];
if(datosRequest != null)
{
//do something
hidden1.Value = datosRequest ;
}
}
else
{
datosRequest = hidden1.Value;
}
I have solved the problem. I was thinking a bit and detects when passed a second time to obtain the pdf that was creating the cookie to be passed to the other form was created and therefore did not pass the data. for this reason I had to add 2 lines but my code for closing the pdf this server delete the cookie and when consulted again remove the client:
Response.Cookies.Clear ();
myCookie.Expires = DateTime.Now.AddDays (1D);
Related
SOLVED
The problem was sending the number with double quotes like "40".
So I replaced quotes with empty space and It worked.
This is the code.
HRMID = HRMID.Replace('"', ' ').Trim();
I am trying to call my REST service consecutively but only one of them is working when I do that.
If I call only one of them in one block it works but two of them in one function block is causing problems I think,I don't know why.
Maybe it is something about restriction in the service.
There is no Error just it is not updating the Database.
If I use it alone it works so call is correct.
This is my code , I am waiting for suggestions.
Thanks!
private void GameClosed(object sender, EventArgs e)
{
// Do your stuff when the game closed.
try
{
var client = new WebClient();
var result = client.DownloadString(wsUrl + "/rest/gethrmid/" + UserValues[4]);// Only the first REST API call is working.This one works.
MessageBox.Show("Result is :" + result);
string HRMID = result;
StreamReader SR = new StreamReader("D:/HRMSession.txt");
string hrmValues = SR.ReadToEnd();
client.DownloadString(wsUrl + "/rest/inserthrmsession/" + HRMID + "/" + hrmValues);//This one is not working if i put here.
}
catch (Exception a)
{
MessageBox.Show(a.ToString());
}
}
EDIT:
If I write it as hardcoded it works but if I use the value that is coming from first call it doesn't work.
client.DownloadString(wsUrl + "/rest/inserthrmsession/" + 40 + "/" + hrmValues);//Works.
But I can not convert the value of HRMID to Int because operation contract is string...
I'm creating an Outlook Add In, which has a subform. The form has a button on it, through which I would like to generate a mailitem, if the user clicks it. I'd like to auto-populate some info in the email, and then leave it for the user to send at their leisure.
My code looks like the following:
private void btnMailDocNotice_Click(object sender, EventArgs e)
{
string clientInfo = string.Empty;
string matInfo = string.Empty;
string author = string.Empty;
string dType = string.Empty;
string fLocation = string.Empty;
string keyWords = string.Empty;
string docName = string.Empty;
clientInfo = this.mCboClient.Text + " " + lblClient;
matInfo = this.mCboMatter.Text + " " + lblMatter;
author = this.txtAuthor.Text;
dType = this.mCboDocType.Text.ToUpper();
fLocation = this.txtSavePath.Text;
keyWords = this.txtKeyWords.Text;
docName = this.txtDocName.Text;
this.sendDocNotice = true;
this.Hide();
CreateMailItem(clientInfo, matInfo, author, dType, this.operatorCode.ToUpper(), fLocation, keyWords, docName);
this.Show();
}
private void CreateMailItem(string clientInfo, string matInfo, string author, string dType, string profiledBy, string fLocation, string keyWords, string docName)
{
this.DNoticeItem = (Outlook.MailItem)ThisAddIn.myApp.CreateItem(Outlook.OlItemType.olMailItem);
this.DNoticeItem.Subject = "Document: " + docName;
this.DNoticeItem.HTMLBody = "<span style=\"font-family:Calibri; font-size: 11pt;\">KeyWords: " + keyWords + "</span>";
this.DNoticeItem.HTMLBody += "<br />Client: " + clientInfo;
this.DNoticeItem.HTMLBody += "<br />Matter: " + matInfo;
this.DNoticeItem.HTMLBody += "<br />Author: " + author;
this.DNoticeItem.HTMLBody += "<br />Doc Type: " + dtClient;
this.DNoticeItem.HTMLBody += "<br />Profiled by: " + profiledBy;
this.DNoticeItem.HTMLBody += "<br />File://" + fLocation;
this.DNoticeItem.Importance = Outlook.OlImportance.olImportanceNormal;
this.DNoticeItem.Display(false);
}
The problem that I'm running into, is it fires an exception on the mailitem.display function, whether I use true or false (doing a bit of research says that determines if the user can access the main Outlook window or not while the mailitem is open). The exception is a COM Exception of "A dialog box is open. Close it and try again". I've tried hiding the WinForm prior to the function call that creates the mail item, then show it again after the function is exited, but it didn't work. I've tried a version of the code where I use System.Diagnostics.Process.Start() to try and open the file after saving it to disk, and while it doesn't fire an exception from the add in, Outlook prompts the user with a message box of the same message from the ComException. I even tried creating a field to see if the doc notice email should be drafted, and thought to have the code take care of that after a form.close() call, thinking the close call would at least dispose of the dialog box that was locking Outlook, and I still got the same exception.
Is there a way to achieve what I want? Does anyone have any suggestions? I'm kind of stuck at the moment, and would appreciate any help/pointers/suggestions anyone has to offer in this issue. My sincere apologies if this is a duplicative question - I couldn't find a good answer to the question. Thank you in advance for your time.
Firstly, why not display yoru own form modelessly?
Secondly (and this is pretty important) do not use code like the following
this.DNoticeItem.HTMLBody += "<br />Client: " + clientInfo;
Every time you run a line like that, you retrieve HTMLBody, add some stuff to it (making the HTML malformed), then set HTMLBody again and force Outlook to make sense of your (malformed) HTML. This (assuming Outlook can parse and fix your HTML) will result in HTML being returned to be different from what you set it to.
Build the HTML body once using a regular string, and set HTMLBody property only once.
We are moving from Reporting Services remote to local,for this i've been converting the rdl files to rdlc successfully and changing the reportviewers to local processing and passing the data source via code like this:
ReportDataSource data = new ReportDataSource("PARAGAINSA", new InventarioRptCs().Selecciona_Saldos_Articulo(locid,
BodId,depid,FamId,NBid,imId,desde,hasta));
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(data);
ReportViewer1.LocalReport.Refresh();
Works great, i've also encounter some reports that have some subreports to pass the data source to the sub reports i've been doing it like this:
ReportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(SubReporteHandler);
private void SubReporteHandler(object sender, SubreportProcessingEventArgs e)
{
int im_id = Convert.ToInt32(e.Parameters[1].Values[0].ToString());
int loc_id = Convert.ToInt32(e.Parameters[0].Values[0]);
e.DataSources.Add(new ReportDataSource("PARAGAINSA", new InventarioRptCs().Selecciona_Saldos_Articulo_Det(loc_id,im_id)));
}
it also worked great, so i happily continue until i find a Report that has a subreport and the subreport has this in one of the fields:
when i click on the field that acts as the navigation link to the other report i get this
A data source instance has not been supplied for the data source 'datasource'.
so my question is: is there anyway i can pass the data source to the report inside the sub report that is been call via navigation -> go to report? if so how?
I am using VS 2013, with SQL server 2012
Thank you for reading, pardon my english not my first languague
Since i was not able to find another way to solve this i did the following to try and simulate the navigation between reports that is only available(to my knowledge) in processing mode remote,
First in the rdlc file i added 'Ver mas informacion' in the title property of the column that was acting as the link to the other report and set the Color to blue to give it a link style
i had to add the tooltip(rendes to title attribute) because i was not able to find another way to be able to select those specific cells that i wanted
then a css style to set the Cursor to pointer
[title="Ver mas informacion"] {
cursor:pointer;
}
then a script using jquery to handle the click event geting the values that i need as a parameter to the other report, navigate to the other report and pass the parameter via URL
$(window).load(function () {
$(document).on('click', '[title="Ver mas informacion"]', function () {
var locId = $('[id$="ddLocal"]').val();
var Fecha = $(this).parent().parent()[0].childNodes[2].childNodes[0].innerHTML;
var TT_Id = $(this).parent().parent()[0].childNodes[9].childNodes[0].innerHTML;
var Ap_Id = $(this).parent().parent()[0].childNodes[10].childNodes[0].innerHTML;
window.open(window.location.origin + config.base + '/Reportes/RptSubViewer.aspx?Sub=Doc&Loc=' + locId + '&Fecha=' + Fecha + '&AP=' + Ap_Id + '&TT_Id=' + TT_Id);
});
});
then over the other webform i only added a reportviewer and on the code behind
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Request.QueryString["Sub"] == "Doc")
{
string _loc = Request.QueryString["Loc"];
string _fecha = Request.QueryString["Fecha"];
string _Ap_Id = Request.QueryString["AP"];
string _TT_Id = Request.QueryString["TT_Id"];
int loc_id = 0, TT_id = 0, Ap_Id = 0;
CultureInfo provider = new CultureInfo("en-US");
DateTime Fecha = DateTime.Now;
if (!string.IsNullOrEmpty(_loc))
loc_id = Convert.ToInt32(_loc);
if (!string.IsNullOrEmpty(_fecha))
Fecha = DateTime.ParseExact(_fecha,"dd/MMM/yyyy",provider);
if (!string.IsNullOrEmpty(_Ap_Id))
Ap_Id = Convert.ToInt32(_Ap_Id);
if (!string.IsNullOrEmpty(_TT_Id))
TT_id = Convert.ToInt32(_TT_Id);
if (TT_id == 14 || TT_id == 15 || TT_id == 21)
{
List<ReportParameter> paramList = new List<ReportParameter>();
paramList.Add(new ReportParameter("LocId", _loc));
paramList.Add(new ReportParameter("Fecha", Fecha.ToShortDateString()));
paramList.Add(new ReportParameter("TT_Id", _TT_Id));
paramList.Add(new ReportParameter("TT_Doc", _Ap_Id));
ReportDataSource data = new ReportDataSource("ARACLDS", new InventarioRptCs().Selecciona_Saldos_Articulo_Doc(loc_id, Fecha, TT_id, Ap_Id).ToList());
RVSubNav.LocalReport.ReportPath = "Rdlcs\\ReporteKardexDoc.rdlc";
RVSubNav.Visible = true;
RVSubNav.LocalReport.SetParameters(paramList);
RVSubNav.LocalReport.DataSources.Clear();
RVSubNav.LocalReport.DataSources.Add(data);
RVSubNav.LocalReport.Refresh();
}
}
}
}
not sure if the best way but it got the job done
I am desperately in need of debugging help, been stuck at this error for 6 days now.....
the error I get in my ASp.net app is :
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near '<script type='text/j'.
Below is the relevant code snippet,
CollyDataExchangeWebService Col_ValSub = new CollyDataExchangeWebService();
CollyReportServiceRequest ServiceReq = new CollyReportServiceRequest();
CollyReportServiceRequestData ServiceReqData = new CollyReportServiceRequestData();
ServiceReqData.AmendmentIndicatorSpecified = true;
ServiceReqData.AmendmentIndicator = false;
ServiceReqData.CollyReport = ColRep;
ServiceReq.ServiceRequestData = ServiceReqData;
ServiceReq.ServiceRequestHeader = ServiceHeader;
errValidate = null;
//btnOK.OnClientClick = "MSGShow()";
bool Valid = true;
string ErrMsgs = "";
if (((System.Web.UI.WebControls.Button)(sender)).CommandArgument == "Validate")
{
CollyReportServiceResponse ValResponse = Col_ValSub.validateReport(ServiceReq);
switch (ValResponse.ServiceResponseHeader.ServiceStatus)
{
case ServiceStatus.Successful:
btnOK.OnClientClick = "";
valHeader.Text = "Validation is Completed. No errors were found";
mlValPopup.Show();
break;
case ServiceStatus.ValidationErrors:
Valid = false;
ErrMsgs = ErrMsgs + _ValidationError(ValResponse);
ValBTN.Update();
mlValPopup.Show();
break;
case ServiceStatus.SystemError:
btnOK.OnClientClick = "";
Valid = false;
ErrMsgs = ErrMsgs + _SystemError(ValResponse);
ValBTN.Update();
mlValPopup.Show();
break;
}
After hours of debugging I found this line to be causing the error:
CollyReportServiceResponse ValResponse = Col_ValSub.validateReport(ServiceReq);
After 6 days of debugging and frustration I found that SOME records cause this issue and others dont in OLDER versions of the code but in new version ALL of the records lead to this error so it has to do something with the data in the DB which means SOME method in the code behaves differently to nulls but I cant find out exactly what the issue is because my app is 30k lines of code
after searching around and trying various solutions, the below 2 are not the solutions to my issue.
forums.asp.net/t/1357862.aspx
http://www.vbforums.com/showthread.php?t=656246
I want to mention that I am already having a difficult time dealing with this application because it was written by other programmers that are now long gone leaving behind non-documented or commented spaghetti code.
I did not code this but other programmers from past have put Response.Write in code:
private void MessageBox(string msg)
{
if (!string.IsNullOrEmpty(msg))
{
Global.tmpmsg = msg;
msg = null;
}
Response.Write("<script type=\"text/javascript\" language=\"javascript\">");
Response.Write("window.open('ErrorPage.aspx?msg=" + "','PopUp','screenX=0,screenY=0,width=700,height=340,resizable=1,status=no,scrollbars=yes,toolbars=no');");
Response.Write("</script>");
}
This one is in another method:
Response.Write("<script type=\"text/javascript\" language=\"javascript\">");
Response.Write("alert('No search resuls were found');");
Response.Write("</script>");
Or This:
if (!string.IsNullOrEmpty(msg))
{
Global.tmpmsg = msg;
Response.Write("<script type=\"text/javascript\" language=\"javascript\">");
Response.Write("window.open('ErrorPage.aspx?msg=" + "','PopUp','screenX=0,screenY=0,width=700,height=340,resizable=1,status=no,scrollbars=yes,toolbars=no');");
Response.Write("</script>");
}
After Jrummel`s comment I added this to code and then nothing at all happened.
private void MessageBox(string msg)
{/*
if (!string.IsNullOrEmpty(msg))
{
Global.tmpmsg = msg;
msg = null;
}
Response.Write("<script type=\"text/javascript\" language=\"javascript\">");
Response.Write("window.open('ErrorPage.aspx?msg=" + "','PopUp','screenX=0,screenY=0,width=700,height=340,resizable=1,status=no,scrollbars=yes,toolbars=no');");
Response.Write("</script>");
*/
// Define the name and type of the client scripts on the page.
String csname1 = "PopupScript";
Type cstype = this.GetType();
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname1))
{
String cstext1 = "<script type=\"text/javascript\" language=\"javascript\">" + " " + "window.open('ErrorPage.aspx?msg=" + "','PopUp','screenX=0,screenY=0,width=700,height=340,resizable=1,status=no,scrollbars=yes,toolbars=no');" + " " + "</script>";
cs.RegisterStartupScript(cstype, csname1, cstext1, false);
}
}
I have found the error after 2 weeks of debugging and 2 days of Brute Forcing:
In one of the 800 DB columns that I have there was a null/improper value. This value reacted with one of the 150 methods in my ASP.NET code in such a way as to present a JavaScript error even though Response.Write() was NOT the issue. I have not found which method it was that reacted to this value but I have found the solution which is to simply input a valid value on the column record..
How a programmer can brute force to find the issue:
In my case after long days of debugging I took a sample of one working record and another sample of an error leading record. Once I had achieved this, I used
DELETE FROM tablename WHERE UniqueColID= unique identifier for the error causing record
Then I did:
INSERT INTO tablename ([uniqueIdentifier],[ column 2],[column 3]) SELECT #UniqueIdentifierofErrorCausingRecord, column2, [column3] FROM TableName WHERE [uniqueIdentifier]=#UniqueIdentifierForWorkingRecord;
What the first statement does is delete the non working record then the 2nd statement reinserts that record with identical column values of the working record but with the UniqueIdentifier of the Non working record. This way I can go through each table to find which table is causing the error and then I can pinpoint which column of that table is the issue.
The specific issue in my case was DateTime.TryParse() because a table column value was inserted in improper format.. The code performed field population in one of the methods without a try and catch using the DateTime.Parse method.... After some testing it seems even a try/catch is not able to pick this error up as it is a javascript error..
Don't use Response.Write().
Instead, create a LiteralControl and add it to the page.
Use ClientScriptManager to add scripts to the page. Here's an example from MSDN:
// Define the name and type of the client scripts on the page.
String csname1 = "PopupScript";
Type cstype = this.GetType();
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname1))
{
String cstext1 = "alert('Hello World');";
cs.RegisterStartupScript(cstype, csname1, cstext1, true);
}
Is anyone having any experience with any eCommerce application where you have calculated shipping rate on fly. I am in particular referring to Australia Post service.
Could you please guide me in right direction. I am thinking of using Provider pattern by which I can plugin any shipping provider according to user's profile.
Explanation as per Australia Post is what I am looking for but if anyone has got any suggestions using any other provider, I am fine.
FYI - I am referring to ASP.net, c# (.Net 4.0)
Thanks in advance,
Australia Post has a Delivery Rate Calculator API.
The following instructions have been developed to enable you to access the functionality of the Post eDeliver Delivery Rate Calculator (DRC) directly from your merchant Website. The DRC is available to merchants who would like to offer online estimation of delivery charges to their customers.
I haven't used it so can't tell you anymore about it.
Step-1: create account and get Key
http://auspost.com.au/
Step2 : create function in your MyPage.aspx.cs page
protected string CalculateCharge(string lngth, string wdth, string hgth, string fpcode, string tpcode, string weght, string service_code)
{
string url = "https://auspost.com.au/api/postage/parcel/domestic/calculate.xml?";
url = url + "length=" + HttpUtility.UrlEncode(lngth) + "&width=" + HttpUtility.UrlEncode(wdth) + "&height=" + HttpUtility.UrlEncode(hgth) + "&from_postcode=" + HttpUtility.UrlEncode(fpcode) + "&to_postcode=" + HttpUtility.UrlEncode(tpcode) + "&option_code=&weight=" + HttpUtility.UrlEncode(weght) + "&service_code=" + HttpUtility.UrlEncode(service_code) + "&extra_cover=";
Uri objURI = new Uri(url);
HttpWebRequest objwebreq = (HttpWebRequest)WebRequest.Create(objURI);
objwebreq.ContentType = "text/xml;charset=utf-8;";
objwebreq.Method = "Get";
objwebreq.Timeout = 15000;
objwebreq.Headers.Set("AUTH-KEY", "here enter your key");
HttpWebResponse objWebResponse = (HttpWebResponse)objwebreq.GetResponse();
Stream objStream = objWebResponse.GetResponseStream();
StreamReader objStreamReader = new StreamReader(objStream);
return objStreamReader.ReadToEnd();
}
Step-3: Pass Parameter in function
button click:
protected void btnShippingCalculate_Click(object sender, EventArgs e)
{
string xmlresult = CalculateCharge("10", "10", "10", "3216","3217" ,"5", "AUS_PARCEL_REGULAR");
DataSet ds = new DataSet();
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(xmlresult);
ds.ReadXml(new System.IO.StringReader(doc.OuterXml));
GridView1.DataSource = ds;
GridView1.DataBind();
}
Note:
service_code:
AUS_PARCEL_REGULAR
AUS_PARCEL_EXPRESS
AUS_PARCEL_PLATINUM
Weight: in KG
That's It!!!